Skip to content

Commit

Permalink
Fix a crash in instanceof pattern handling
Browse files Browse the repository at this point in the history
Fixes https://github.com/google/google-java-format

PiperOrigin-RevId: 368720966
  • Loading branch information
cushon authored and google-java-format Team committed Apr 15, 2021
1 parent 5104d0b commit 32b63aa
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
Expand Up @@ -60,7 +60,7 @@ public Void visitBindingPattern(BindingPatternTree node, Void unused) {
} catch (ReflectiveOperationException e1) {
try {
Tree type = (Tree) BindingPatternTree.class.getMethod("getType").invoke(node);
Name name = (Name) BindingPatternTree.class.getMethod("getName").invoke(node);
Name name = (Name) BindingPatternTree.class.getMethod("getBinding").invoke(node);
visitBindingPattern(/* modifiers= */ null, type, name);
} catch (ReflectiveOperationException e2) {
e2.addSuppressed(e1);
Expand Down
Expand Up @@ -48,7 +48,7 @@
public class FormatterIntegrationTest {

private static final ImmutableSet<String> JAVA14_TESTS =
ImmutableSet.of("I477", "Records", "RSLs", "Var", "ExpressionSwitch", "I574");
ImmutableSet.of("I477", "Records", "RSLs", "Var", "ExpressionSwitch", "I574", "I594");

private static final ImmutableSet<String> JAVA16_TESTS = ImmutableSet.of("I588");

Expand Down
@@ -0,0 +1,7 @@
public class I594 {
public void thisIsNotFormattedCorrectly(Object something){
if(something instanceof String somethingAsString){
return;
}
}
}
@@ -0,0 +1,7 @@
public class I594 {
public void thisIsNotFormattedCorrectly(Object something) {
if (something instanceof String somethingAsString) {
return;
}
}
}

0 comments on commit 32b63aa

Please sign in to comment.