File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed
semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac
semanticdb-java/src/main/java/com/sourcegraph/semanticdb_javac Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -190,6 +190,12 @@ public static Semanticdb.Constant doubleConst(Double value) {
190
190
.build ();
191
191
}
192
192
193
+ public static Semanticdb .Constant nullConst () {
194
+ return Semanticdb .Constant .newBuilder ()
195
+ .setNullConstant (Semanticdb .NullConstant .newBuilder ())
196
+ .build ();
197
+ }
198
+
193
199
public static Semanticdb .Constant floatConst (Float value ) {
194
200
return Semanticdb .Constant .newBuilder ()
195
201
.setFloatConstant (Semanticdb .FloatConstant .newBuilder ().setValue (value ))
Original file line number Diff line number Diff line change @@ -118,7 +118,12 @@ private Semanticdb.Tree annotationParameter(ExpressionTree expr) {
118
118
// Literals can either be a primitive or String
119
119
Object value = ((LiteralTree ) expr ).getValue ();
120
120
final Semanticdb .Constant constant ;
121
- if (value instanceof String ) constant = stringConst ((String ) value );
121
+ // Technically, annotation parameter values cannot be null,
122
+ // according to JLS: https://docs.oracle.com/javase/specs/jls/se8/html/jls-9.html#jls-9.7.1
123
+ // But this codepath is still possible to hit when compiling invalid code - and
124
+ // we should handle the null const case in order to fail more gracefully
125
+ if (value == null ) constant = nullConst ();
126
+ else if (value instanceof String ) constant = stringConst ((String ) value );
122
127
else if (value instanceof Boolean ) constant = booleanConst ((Boolean ) value );
123
128
else if (value instanceof Byte ) constant = byteConst ((Byte ) value );
124
129
else if (value instanceof Short ) constant = shortConst ((Short ) value );
You can’t perform that action at this time.
0 commit comments