Skip to content

Commit

Permalink
Handle malformed annotations more gracefully
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cushon authored and ronshapiro committed Jun 7, 2017
1 parent bc94435 commit 9b6d334
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,11 @@ public Void visitAnnotation(AnnotationTree node, Void unused) {
builder.breakOp(" ");
}
}
visitAnnotationArgument((AssignmentTree) argument);
if (argument instanceof AssignmentTree) {
visitAnnotationArgument((AssignmentTree) argument);
} else {
scan(argument, null);
}
first = false;
}
builder.breakOp(UNIFIED, "", minusTwo, Optional.<BreakTag>absent());
Expand All @@ -1253,6 +1257,9 @@ public Void visitAnnotation(AnnotationTree node, Void unused) {
new Predicate<ExpressionTree>() {
@Override
public boolean apply(ExpressionTree argument) {
if (!(argument instanceof AssignmentTree)) {
return false;
}
ExpressionTree expression = ((AssignmentTree) argument).getExpression();
return expression instanceof NewArrayTree
&& ((NewArrayTree) expression).getType() == null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@Redacted(Redacted.REDACTED + "/redacted", redacted = Redacted.class)
class B38352414 {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@Redacted(Redacted.REDACTED + "/redacted", redacted = Redacted.class)
class B38352414 {}

0 comments on commit 9b6d334

Please sign in to comment.