Skip to content

Commit

Permalink
Fix for a crash in RedundantSetterCall.
Browse files Browse the repository at this point in the history
[]

PiperOrigin-RevId: 627663284
  • Loading branch information
graememorgan authored and Error Prone Team committed Apr 24, 2024
1 parent 92c106d commit 3ee6f41
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static com.google.errorprone.util.ASTHelpers.getEnclosedElements;
import static com.google.errorprone.util.ASTHelpers.getSymbol;
import static com.google.errorprone.util.ASTHelpers.getType;
import static com.google.errorprone.util.ASTHelpers.getUpperBound;
import static com.google.errorprone.util.ASTHelpers.hasAnnotation;
import static com.google.errorprone.util.ASTHelpers.isAbstract;
import static com.google.errorprone.util.ASTHelpers.isSameType;
Expand Down Expand Up @@ -164,7 +165,7 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState
}

private ImmutableMap<String, OneOfField> scanForOneOfSetters(Type type, VisitorState state) {
var owner = type.tsym.owner;
var owner = getUpperBound(type, state.getTypes()).tsym.owner;
if (owner == null || isSubtype(owner.type, GENERATED_MESSAGE_LITE.get(state), state)) {
return ImmutableMap.of();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,19 @@ public void autovalue() {
"}")
.doTest();
}

@Test
public void builderOfWildcardType_noFindings() {
compilationHelper
.addSourceLines(
"Test.java",
"import com.google.protobuf.Descriptors.FieldDescriptor;",
"import com.google.protobuf.GeneratedMessage.Builder;",
"class Test {",
" public void clear(final Builder<?> builder, FieldDescriptor fieldDescriptor) {",
" builder.clearField(fieldDescriptor);",
" }",
"}")
.doTest();
}
}

0 comments on commit 3ee6f41

Please sign in to comment.