diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/SetUnrecognized.java b/core/src/main/java/com/google/errorprone/bugpatterns/SetUnrecognized.java index afc49c81a3b..168c5c6e458 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/SetUnrecognized.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/SetUnrecognized.java @@ -50,6 +50,9 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState } ExpressionTree arg = tree.getArguments().get(0); var argSymbol = getSymbol(arg); + if (argSymbol == null) { + return NO_MATCH; + } if (!argSymbol.getSimpleName().contentEquals("UNRECOGNIZED")) { return NO_MATCH; } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/SetUnrecognizedTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/SetUnrecognizedTest.java index 860a4fdb82d..7c55a108c84 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/SetUnrecognizedTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/SetUnrecognizedTest.java @@ -56,4 +56,19 @@ public void negative() { "}") .doTest(); } + + @Test + public void negativeNotEnum() { + compilationHelper + .addSourceLines( + "Test.java", + "import com.google.errorprone.bugpatterns.proto.Proto3Test.TestProto3Enum;", + "import com.google.errorprone.bugpatterns.proto.Proto3Test.TestProto3Message;", + "class Test {", + " void test() {", + " TestProto3Message.newBuilder().setMyString(\"\");", + " }", + "}") + .doTest(); + } }