Skip to content

Commit 01e4a83

Browse files
alorenzennatebosch
authored andcommitted
Fix NPE when ElementAnnotation.constantValue returns null. (#89)
Instead of throwing a NPE, throw an ArgumentError with a message to suggest that a dependency might be missing.
1 parent 9514c57 commit 01e4a83

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/src/annotation.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,11 @@ bool matchAnnotation(Type annotationType, ElementAnnotation annotation) {
211211
var classMirror = reflectClass(annotationType);
212212
var classMirrorSymbol = classMirror.simpleName;
213213

214-
var annotationValueType = annotation.constantValue.type;
214+
var annotationValueType = annotation.constantValue?.type;
215+
if (annotationValueType == null) {
216+
throw new ArgumentError.value(annotation, 'annotation',
217+
'Could not determine type of annotation. Are you missing a dependency?');
218+
}
215219

216220
var annTypeName = annotationValueType.name;
217221
var annotationTypeSymbol = new Symbol(annTypeName);

0 commit comments

Comments
 (0)