Skip to content

Commit 9b6d334

Browse files
cushonronshapiro
authored andcommitted
Handle malformed annotations more gracefully
javac's parser doesn't weed annotations with illegal combinations of assignment and non-assignment expressions, so don't crash when formatting them. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=157855678
1 parent bc94435 commit 9b6d334

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,11 @@ public Void visitAnnotation(AnnotationTree node, Void unused) {
12321232
builder.breakOp(" ");
12331233
}
12341234
}
1235-
visitAnnotationArgument((AssignmentTree) argument);
1235+
if (argument instanceof AssignmentTree) {
1236+
visitAnnotationArgument((AssignmentTree) argument);
1237+
} else {
1238+
scan(argument, null);
1239+
}
12361240
first = false;
12371241
}
12381242
builder.breakOp(UNIFIED, "", minusTwo, Optional.<BreakTag>absent());
@@ -1253,6 +1257,9 @@ public Void visitAnnotation(AnnotationTree node, Void unused) {
12531257
new Predicate<ExpressionTree>() {
12541258
@Override
12551259
public boolean apply(ExpressionTree argument) {
1260+
if (!(argument instanceof AssignmentTree)) {
1261+
return false;
1262+
}
12561263
ExpressionTree expression = ((AssignmentTree) argument).getExpression();
12571264
return expression instanceof NewArrayTree
12581265
&& ((NewArrayTree) expression).getType() == null;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@Redacted(Redacted.REDACTED + "/redacted", redacted = Redacted.class)
2+
class B38352414 {}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@Redacted(Redacted.REDACTED + "/redacted", redacted = Redacted.class)
2+
class B38352414 {}

0 commit comments

Comments
 (0)