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 bug with implicit equals() methods in interfaces #898

Merged
merged 3 commits into from
Jan 25, 2024

Conversation

msridhar
Copy link
Collaborator

Fixes #897

This fixes a regression in our handling of implicit equals() methods in interfaces when building on JDK 21. I see this as an interim fix, until we can fix NullAway to properly always assume / enforce that the parameter of equals() is @Nullable. But, I think we should fix the regression in the short term.

@msridhar msridhar requested a review from yuxincs January 19, 2024 19:13
Copy link

codecov bot commented Jan 19, 2024

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (c1eb8ca) 86.95% compared to head (aa12d03) 86.96%.

Files Patch % Lines
...away/src/main/java/com/uber/nullaway/NullAway.java 75.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #898      +/-   ##
============================================
+ Coverage     86.95%   86.96%   +0.01%     
- Complexity     1953     1956       +3     
============================================
  Files            77       77              
  Lines          6315     6320       +5     
  Branches       1222     1224       +2     
============================================
+ Hits           5491     5496       +5     
+ Misses          420      419       -1     
- Partials        404      405       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -985,4 +985,20 @@ public void cfgConstructionSymbolCompletionFailure() {
"}")
.doTest();
}

@Test
public void testDefaultEqualsInInterfaceTakesNullable() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this PR, this test would fail in the :nullaway:testJdk21 task

Copy link
Collaborator

@yuxincs yuxincs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just have a clarifying question due to my insufficient knowledge of the codebase, but the change LGTM!

Comment on lines +419 to +426
if (methodSymbol.owner.isInterface()) {
Symbol.MethodSymbol baseSymbol = (Symbol.MethodSymbol) methodSymbol.baseSymbol();
if (baseSymbol != methodSymbol && baseSymbol.owner == state.getSymtab().objectType.tsym) {
methodSymbol = baseSymbol;
}
}
return methodSymbol;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if I'm understanding this wrong, but previously we would get a symbol from the interface, which would eventually be considered annotated in the caller (matchMethodInvocation and later handleInvocation).

Now that we have this special handling to resolve to the base symbol (i.e., from java.lang.Object), which would be considered unannotated (everything from the JDK is unannotated), and then NullAway won't think that equals must have a nonnull param. Right?

If so, this change looks good to me! (I also agree that this is the interim solution and the end goal is for NullAway to enforce nullable on equals, but that's for another PR)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yuxincs yes, this is exactly correct.

@msridhar msridhar merged commit b94597a into uber:master Jan 25, 2024
11 of 12 checks passed
@msridhar msridhar deleted the issue-897-nullable-equals-jdk21 branch January 25, 2024 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False positive on equals(nullable) when using NullAway with Java 21.
2 participants