-
Notifications
You must be signed in to change notification settings - Fork 578
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
NP_METHOD_PARAMETER_TIGHTENS_ANNOTATION erroneously issued on equals(@Nullable Object) #633
Comments
I can reproduce this. There's no annotation on |
OK, having dug around a bit, this stems from the fact that FindBugs (since 2007) implicitly adds a So I don't understand why anyone would annotate an The resulting message could be better, however; perhaps annotating |
I have to admit I was not aware of I would be happy switching to annotating my |
Yeah, apparently Nullable is supposed to behave as if there were no annotation at all. Though in this case there's a conflict. I won't close this yet, because we should do some better handling of this case (and perhaps similar ones). |
I have a somewhat radical suggestion. How about we treat As I understand it, This will also work for all the people who have been using |
I 100% agree that this is a non-intuitive error. Especially when combined with this issue here in the Kotlin compiler: |
+1 This is a non-intuitive error, please resolve. |
@ThrawnCA Any objections to my suggestion above to treat |
@marquiswang That would need to be discussed with @spotbugs/everyone, not just me. |
Is there a process for that discussion? |
No well-defined process we have, just have discussion at here then it's OK. To keep backward compatibility (at least in 3.1.x release), I prefer not changing behaviour but adding another bug pattern that detects misuse of I know JSR305 and spotbugs-annotations are not intuitive. However changing their behaviour will introduce more and different complexity. So if we need different behaviour, it's better to migrate to another solution like annotation provided by Checker Framework, I think. |
I can't remember if I've asked this few years ago on the FB list, what is the rationale behind The javadoc on them explains it:
The presence of two different annotations in FB is highly surprising for everyone, especially because Eclipse (and the rest of the world) used their versions of So, in my POV this was an unfortunate decision in the very early days of NP analysis invented by JSR-305 authors. As a result, very surprising, if I remember it right, FB will not warn about possible NPE on dereferencing values marked as Ideally we would change However, this will be a breaking change for all FindBugs/SpotBugs users, and probably also to the FB engine itself. I have now no real insights how deep in the FB engine the difference is rooted and how much code we need to change to remove this "duality of null annotations". So if we would do this, we should do this on 4.x branch. |
I too was surprised to find that there is both Conceptually, I kind of like the concept of having a third nullability annotation that covers some of the weird edge cases where technically a field or a method can be null but you can be confident that it never will. On example is two fields for which you know that exactly one is always null. They are both |
First time spotbugs user here. I have this problem with auto-generated source code from the Immutables library. A bit of googling shows that Findbugs had this issue as well back in 2017 https://stackoverflow.com/questions/46760970/immutables-lib-adds-nullable-to-equals-method Is there any progress on this issue? |
FWIW I do sometimes use |
If I add an equals override with a @javax.annotation.Nullable annotation (from com.google.code.findbugs:jsr305), I get an NP_METHOD_PARAMETER_TIGHTENS_ANNOTATION
"M D NP: Method TestObject.equals(Object) overrides the nullness annotation of parameter other in an incompatible way At TestObject.java:[lines 6-12]"
The description on the error says:
This shouldn't be applying, since we're overriding with @nullable.
The text was updated successfully, but these errors were encountered: