-
Notifications
You must be signed in to change notification settings - Fork 299
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
Conversation
|
||
/** | ||
* 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; | ||
} |
There was a problem hiding this comment.
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
Codecov ReportAttention:
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🚀
#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.
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-generatedequals()
method.The real logic change in this PR is very small. Most of the changes are required to make a
VisitorState
object available in aHandler
method.