Commit 1ee31e73 authored by Stephane Nicoll's avatar Stephane Nicoll

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
parent 2b6d7a3f
...@@ -118,9 +118,12 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor ...@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment