Skip to content

Commit

Permalink
Don't scan into nested enums in ClassInitializationDeadlock
Browse files Browse the repository at this point in the history
#4378

PiperOrigin-RevId: 629452163
  • Loading branch information
cushon authored and Error Prone Team committed Apr 30, 2024
1 parent c8df502 commit 6a8f493
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public Description matchClass(ClassTree tree, VisitorState state) {
@Override
public Void visitClass(ClassTree node, Void unused) {
for (Tree member : node.getMembers()) {
if (member.getKind().equals(Tree.Kind.CLASS)) {
if (member instanceof ClassTree) {
continue;
}
scan(member, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,34 @@ public void negativeNonPrivateUnrelatedSuper() {
"}")
.doTest();
}

@Test
public void nestedEnum() {
testHelper
.addSourceLines(
"TestInterface.java", //
"public interface TestInterface {",
" default Object foo() {",
" return null;",
" }",
" enum TestEnum implements TestInterface {",
" INSTANCE;",
" }",
"}")
.doTest();
}

@Test
public void nestedInterface() {
testHelper
.addSourceLines(
"Foo.java", //
"interface Foo {",
" default void foo() {}",
" interface Sub extends Foo {",
" final Sub INSTANCE = new Sub() {};",
" }",
"}")
.doTest();
}
}

0 comments on commit 6a8f493

Please sign in to comment.