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.
pull/2479/merge
Phillip Webb 10 years ago
parent 10257d96f2
commit 1f0d45d795

@ -101,7 +101,8 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
super.init(env);
this.typeUtils = new TypeUtils(env);
this.metadataStore = new MetadataStore(env);
this.metadataCollector = new MetadataCollector(env, this.metadataStore.readMetadata());
this.metadataCollector = new MetadataCollector(env,
this.metadataStore.readMetadata());
try {
this.fieldValuesParser = new JavaCompilerFieldValuesParser(env);
}
@ -128,10 +129,11 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
}
private void processElement(Element element) {
try {
AnnotationMirror annotation = getAnnotation(element,
configurationPropertiesAnnotation());
String prefix = getPrefix(annotation);
if (annotation != null) {
String prefix = getPrefix(annotation);
if (element instanceof TypeElement) {
processAnnotatedTypeElement(prefix, (TypeElement) element);
}
@ -140,6 +142,11 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
}
}
}
catch (Exception ex) {
throw new IllegalStateException(
"Error processing configuration meta-data on " + element, ex);
}
}
private void processAnnotatedTypeElement(String prefix, TypeElement element) {
String type = this.typeUtils.getType(element);

Loading…
Cancel
Save