Skip to content

Commit 1f0d45d

Browse files
committed
Protect against NPE and improve error message
Update ConfigurationMetadataAnnotationProcessor so that `prefix` is only obtained when the annotation is not null. Also improve exception message by including the element.
1 parent 10257d9 commit 1f0d45d

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ public synchronized void init(ProcessingEnvironment env) {
101101
super.init(env);
102102
this.typeUtils = new TypeUtils(env);
103103
this.metadataStore = new MetadataStore(env);
104-
this.metadataCollector = new MetadataCollector(env, this.metadataStore.readMetadata());
104+
this.metadataCollector = new MetadataCollector(env,
105+
this.metadataStore.readMetadata());
105106
try {
106107
this.fieldValuesParser = new JavaCompilerFieldValuesParser(env);
107108
}
@@ -128,17 +129,23 @@ public boolean process(Set<? extends TypeElement> annotations,
128129
}
129130

130131
private void processElement(Element element) {
131-
AnnotationMirror annotation = getAnnotation(element,
132-
configurationPropertiesAnnotation());
133-
String prefix = getPrefix(annotation);
134-
if (annotation != null) {
135-
if (element instanceof TypeElement) {
136-
processAnnotatedTypeElement(prefix, (TypeElement) element);
137-
}
138-
else if (element instanceof ExecutableElement) {
139-
processExecutableElement(prefix, (ExecutableElement) element);
132+
try {
133+
AnnotationMirror annotation = getAnnotation(element,
134+
configurationPropertiesAnnotation());
135+
if (annotation != null) {
136+
String prefix = getPrefix(annotation);
137+
if (element instanceof TypeElement) {
138+
processAnnotatedTypeElement(prefix, (TypeElement) element);
139+
}
140+
else if (element instanceof ExecutableElement) {
141+
processExecutableElement(prefix, (ExecutableElement) element);
142+
}
140143
}
141144
}
145+
catch (Exception ex) {
146+
throw new IllegalStateException(
147+
"Error processing configuration meta-data on " + element, ex);
148+
}
142149
}
143150

144151
private void processAnnotatedTypeElement(String prefix, TypeElement element) {

0 commit comments

Comments
 (0)