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

Model Lombok-generated equals methods as having a @Nullable parameter #874

Merged
merged 4 commits into from
Dec 6, 2023

Conversation

msridhar
Copy link
Collaborator

@msridhar msridhar commented Dec 6, 2023

See the new test in UsesDTO. Without this change, NullAway reports an incorrect warning for this code that passes a @Nullable parameter to a Lombok-generated equals() method.

The real logic change in this PR is very small. Most of the changes are required to make a VisitorState object available in a Handler method.

Comment on lines +89 to +110

/**
* Mark the first argument of Lombok-generated {@code equals} methods as {@code @Nullable}, since
* Lombok does not generate the annotation.
*/
@Override
public Nullness[] onOverrideMethodInvocationParametersNullability(
VisitorState state,
Symbol.MethodSymbol methodSymbol,
boolean isAnnotated,
Nullness[] argumentPositionNullness) {
if (ASTHelpers.hasAnnotation(methodSymbol, LOMBOK_GENERATED_ANNOTATION_NAME, state)) {
// We assume that Lombok-generated equals methods with a single argument override
// Object.equals and are not an overload.
if (methodSymbol.getSimpleName().contentEquals("equals")
&& methodSymbol.params().size() == 1) {
// The parameter is not annotated with @Nullable, but it should be.
argumentPositionNullness[0] = Nullness.NULLABLE;
}
}
return argumentPositionNullness;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the only real logic change

Copy link

codecov bot commented Dec 6, 2023

Codecov Report

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

Comparison is base (2f1cf7c) 87.06% compared to head (e178899) 87.03%.

Files Patch % Lines
...java/com/uber/nullaway/handlers/LombokHandler.java 40.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #874      +/-   ##
============================================
- Coverage     87.06%   87.03%   -0.04%     
- Complexity     1924     1926       +2     
============================================
  Files            77       77              
  Lines          6225     6231       +6     
  Branches       1209     1212       +3     
============================================
+ Hits           5420     5423       +3     
- Misses          403      405       +2     
- Partials        402      403       +1     

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

Copy link
Collaborator

@lazaroclapp lazaroclapp left a comment

Choose a reason for hiding this comment

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

LGTM! 🚀

@msridhar msridhar merged commit 5fbee1f into master Dec 6, 2023
8 of 10 checks passed
@msridhar msridhar deleted the lombok-data-equals branch December 6, 2023 13:18
msridhar added a commit to msridhar/NullAway that referenced this pull request Dec 27, 2023
msridhar added a commit that referenced this pull request Dec 27, 2023
#886)

…arameter (#874)"

This reverts commit 5fbee1f.

It turns out that this change requires a couple of other changes along
with it, including #880 and better overall checking of overriding of
`equals()` methods. We want to get a release out soon, so temporarily
revert this change; we will restore it after cutting the release.
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.

2 participants