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:
Stephane Nicoll 2015-08-10 16:34:30 +02:00
parent 2b6d7a3f15
commit 1ee31e73d3

View File

@ -118,9 +118,12 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
RoundEnvironment roundEnv) {
this.metadataCollector.processing(roundEnv);
Elements elementUtils = this.processingEnv.getElementUtils();
for (Element element : roundEnv.getElementsAnnotatedWith(elementUtils
.getTypeElement(configurationPropertiesAnnotation()))) {
processElement(element);
TypeElement annotationType = elementUtils
.getTypeElement(configurationPropertiesAnnotation());
if (annotationType != null) { // Is @ConfigurationProperties available
for (Element element : roundEnv.getElementsAnnotatedWith(annotationType)) {
processElement(element);
}
}
if (roundEnv.processingOver()) {
writeMetaData();