Avoid NPE if @ConfigurationProperties is not present
The annotation processor detects `@ConfigurationProperties` bean or method definition and merges manual meta-data. The former step will fail with a NPE if the annotation is not present on the classpath. This could happen if the annotation processor is added to a module that is not actually using Spring Boot. We now have a defensive check that skips that steps but still attempts to merge manual meta-data if present. Closes gh-3720
This commit is contained in:
parent
2b6d7a3f15
commit
1ee31e73d3
|
@ -118,9 +118,12 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||||
RoundEnvironment roundEnv) {
|
RoundEnvironment roundEnv) {
|
||||||
this.metadataCollector.processing(roundEnv);
|
this.metadataCollector.processing(roundEnv);
|
||||||
Elements elementUtils = this.processingEnv.getElementUtils();
|
Elements elementUtils = this.processingEnv.getElementUtils();
|
||||||
for (Element element : roundEnv.getElementsAnnotatedWith(elementUtils
|
TypeElement annotationType = elementUtils
|
||||||
.getTypeElement(configurationPropertiesAnnotation()))) {
|
.getTypeElement(configurationPropertiesAnnotation());
|
||||||
processElement(element);
|
if (annotationType != null) { // Is @ConfigurationProperties available
|
||||||
|
for (Element element : roundEnv.getElementsAnnotatedWith(annotationType)) {
|
||||||
|
processElement(element);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (roundEnv.processingOver()) {
|
if (roundEnv.processingOver()) {
|
||||||
writeMetaData();
|
writeMetaData();
|
||||||
|
|
Loading…
Reference in New Issue