mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-15 01:07:30 +08:00
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) {
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user