Skip to content

Commit 1ee31e7

Browse files
committed
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
1 parent 2b6d7a3 commit 1ee31e7

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,12 @@ public boolean process(Set<? extends TypeElement> annotations,
118118
RoundEnvironment roundEnv) {
119119
this.metadataCollector.processing(roundEnv);
120120
Elements elementUtils = this.processingEnv.getElementUtils();
121-
for (Element element : roundEnv.getElementsAnnotatedWith(elementUtils
122-
.getTypeElement(configurationPropertiesAnnotation()))) {
123-
processElement(element);
121+
TypeElement annotationType = elementUtils
122+
.getTypeElement(configurationPropertiesAnnotation());
123+
if (annotationType != null) { // Is @ConfigurationProperties available
124+
for (Element element : roundEnv.getElementsAnnotatedWith(annotationType)) {
125+
processElement(element);
126+
}
124127
}
125128
if (roundEnv.processingOver()) {
126129
writeMetaData();

0 commit comments

Comments
 (0)