Skip to content

Commit ba12d25

Browse files
committed
Don't crash on type annotated varargs parameters
Fixes google#95 MOE_MIGRATED_REVID=139810602
1 parent 3c3dcae commit ba12d25

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,13 +2307,22 @@ private void visitToDeclare(
23072307
Optional<String> trailing) {
23082308
sync(node);
23092309
boolean varargs = (((JCTree.JCVariableDecl) node).mods.flags & Flags.VARARGS) == Flags.VARARGS;
2310+
List<? extends AnnotationTree> varargsAnnotations = ImmutableList.of();
2311+
Tree type = node.getType();
2312+
if (varargs) {
2313+
if (type instanceof AnnotatedTypeTree) {
2314+
varargsAnnotations = ((AnnotatedTypeTree) type).getAnnotations();
2315+
type = ((AnnotatedTypeTree) type).getUnderlyingType();
2316+
}
2317+
type = ((ArrayTypeTree) type).getType();
2318+
}
23102319
declareOne(
23112320
kind,
23122321
annotationsDirection,
23132322
Optional.of(node.getModifiers()),
2314-
varargs ? ((ArrayTypeTree) node.getType()).getType() : node.getType(),
2323+
type,
23152324
VarArgsOrNot.valueOf(varargs),
2316-
/*varargsAnnotations=*/ ImmutableList.<AnnotationTree>of(),
2325+
varargsAnnotations,
23172326
node.getName(),
23182327
"",
23192328
equals,
@@ -2956,7 +2965,7 @@ int declareOne(
29562965
Optional<ModifiersTree> modifiers,
29572966
Tree type,
29582967
VarArgsOrNot isVarargs,
2959-
List<AnnotationTree> varargsAnnotations,
2968+
List<? extends AnnotationTree> varargsAnnotations,
29602969
Name name,
29612970
String op,
29622971
String equals,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class I95 {
2+
public void format2(Object @Nullable ... a2) {}
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class I95 {
2+
public void format2(Object @Nullable ... a2) {}
3+
}

0 commit comments

Comments
 (0)