Commit 1f0d45d7 authored by Phillip Webb's avatar Phillip Webb

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.
parent 10257d96
...@@ -101,7 +101,8 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor ...@@ -101,7 +101,8 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
super.init(env); super.init(env);
this.typeUtils = new TypeUtils(env); this.typeUtils = new TypeUtils(env);
this.metadataStore = new MetadataStore(env); this.metadataStore = new MetadataStore(env);
this.metadataCollector = new MetadataCollector(env, this.metadataStore.readMetadata()); this.metadataCollector = new MetadataCollector(env,
this.metadataStore.readMetadata());
try { try {
this.fieldValuesParser = new JavaCompilerFieldValuesParser(env); this.fieldValuesParser = new JavaCompilerFieldValuesParser(env);
} }
...@@ -128,17 +129,23 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor ...@@ -128,17 +129,23 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
} }
private void processElement(Element element) { private void processElement(Element element) {
AnnotationMirror annotation = getAnnotation(element, try {
configurationPropertiesAnnotation()); AnnotationMirror annotation = getAnnotation(element,
String prefix = getPrefix(annotation); configurationPropertiesAnnotation());
if (annotation != null) { if (annotation != null) {
if (element instanceof TypeElement) { String prefix = getPrefix(annotation);
processAnnotatedTypeElement(prefix, (TypeElement) element); if (element instanceof TypeElement) {
} processAnnotatedTypeElement(prefix, (TypeElement) element);
else if (element instanceof ExecutableElement) { }
processExecutableElement(prefix, (ExecutableElement) element); else if (element instanceof ExecutableElement) {
processExecutableElement(prefix, (ExecutableElement) element);
}
} }
} }
catch (Exception ex) {
throw new IllegalStateException(
"Error processing configuration meta-data on " + element, ex);
}
} }
private void processAnnotatedTypeElement(String prefix, TypeElement element) { private void processAnnotatedTypeElement(String prefix, TypeElement element) {
......
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