diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/MemberName.java b/core/src/main/java/com/google/errorprone/bugpatterns/MemberName.java index 19e60c1734c..6698875f0d7 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/MemberName.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/MemberName.java @@ -102,7 +102,8 @@ public Description matchClass(ClassTree tree, VisitorState state) { ClassSymbol symbol = getSymbol(tree); String name = tree.getSimpleName().toString(); if (name.isEmpty() || isConformantUpperCamelName(name)) { - // name.isEmpty() should not happen normally but could if there are errors. + // The name can be empty for enum member declarations, which are desugared early to class + // declarations. return NO_MATCH; } String renamed = suggestedClassRename(name); diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/MemberNameTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/MemberNameTest.java index 0b60ab6402b..509d93dcbf4 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/MemberNameTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/MemberNameTest.java @@ -622,4 +622,17 @@ public void className_underscore() { "}") .doTest(); } + + @Test + public void enumName() { + helper + .addSourceLines( + "Test.java", // + "enum Test {", + " ONE {", + " void f() {}", + " }", + "}") + .doTest(); + } }