Skip to content

Commit 6083e8a

Browse files
committed
Don't crash on union catch variables with modifiers
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=117583993
1 parent a8be5ba commit 6083e8a

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
import java.util.ArrayDeque;
133133
import java.util.ArrayList;
134134
import java.util.Arrays;
135+
import java.util.Collections;
135136
import java.util.Deque;
136137
import java.util.EnumSet;
137138
import java.util.HashMap;
@@ -2332,6 +2333,8 @@ private void visitUnionType(SingleVariableDeclaration declaration) {
23322333
UnionType type = (UnionType) declaration.getType();
23332334
builder.open(ZERO);
23342335
sync(declaration);
2336+
visitAndBreakModifiers(
2337+
declaration.modifiers(), Direction.HORIZONTAL, Optional.<BreakTag>absent());
23352338
List<Type> union = type.types();
23362339
boolean first = true;
23372340
for (int i = 0; i < union.size() - 1; i++) {
@@ -2351,7 +2354,7 @@ private void visitUnionType(SingleVariableDeclaration declaration) {
23512354
declareOne(
23522355
declaration,
23532356
Direction.HORIZONTAL,
2354-
declaration.modifiers(),
2357+
Collections.<IExtendedModifier>emptyList(),
23552358
last,
23562359
VarArgsOrNot.valueOf(declaration.isVarargs()),
23572360
declaration.varargsAnnotations(),
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class B27602933 {
2+
{
3+
try {
4+
} catch (final A | B x) {
5+
}
6+
7+
try {
8+
} catch (@SuppressWarnings("unused") IllegalArgumentException | RuntimeException e) {
9+
}
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class B27602933 {
2+
{
3+
try {
4+
} catch (final A | B x) {
5+
}
6+
7+
try {
8+
} catch (@SuppressWarnings("unused") IllegalArgumentException | RuntimeException e) {
9+
}
10+
}
11+
}

0 commit comments

Comments
 (0)