Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a crash in YodaCondition #4491

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState
state);
}
if (instanceEqualsInvocation().matches(tree, state)) {
return fix(
tree,
getReceiver(tree),
tree.getArguments().get(0),
/* provideNullSafeFix= */ true,
state);
ExpressionTree receiver = getReceiver(tree);
if (receiver == null) {
// call to equals implicitly qualified by `this`
return NO_MATCH;
}
return fix(tree, receiver, tree.getArguments().get(0), /* provideNullSafeFix= */ true, state);
}
return NO_MATCH;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,22 @@ public void nullableYodaCondition() {
"}")
.doTest();
}

@Test
public void unqualified() {
testHelper
.addSourceLines(
"Test.java",
"import com.google.common.base.Objects;",
"class Test {",
" @Override",
" public boolean equals(Object other) {",
" return Objects.equal(this, other);",
" }",
" public boolean foo(Object other) {",
" return equals(other);",
" }",
"}")
.doTest();
}
}
Loading