Skip to content

Commit

Permalink
Fix an NPE in SetUnrecognized
Browse files Browse the repository at this point in the history
Fixes #4475

PiperOrigin-RevId: 653339273
  • Loading branch information
cushon authored and Error Prone Team committed Jul 17, 2024
1 parent bc33976 commit 81d3127
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit 81d3127

Please sign in to comment.