-
Notifications
You must be signed in to change notification settings - Fork 744
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
Allow Nullable (et al) from other packages than javax.annotation (JSR 305) e.g. org.eclipse.jdt.annotation.Nullable #891
Comments
I'd be happy to accept a PR that adds support to ReturnMissingNullable for any annotation with a matching simple name, regardless of fully-qualified name. |
ReturnMissingNullable does accept any conventional, JSR-305-style, Nullable annotation IIRC. Eclipse's annotation, however, is a type annotation it seems [1] and I don't believe we support those ATM. I understand that it syntactically looks identical but under the hood a type annotation is very different. [1] https://checkerframework.org/releases/2.1.14/api/org/eclipse/jdt/annotation/Nullable.html |
@kevin1e100 yeah you are right it is a Type annotation (so can be placed on more things than only return type). If ReturnMissingNullable already accept any annotations matching the simple name Nullable (so even if not from the package javax.annotation), just not Type annotations, then all I'm proposing here is to relax that constraint - which @eaftan seems to be OK with. I'll see when I can propose a PR for this - probably when it bites me next time! |
see http://errorprone.info/bugpattern/ReturnMissingNullable fixed in google/error-prone#723 also note google/error-prone#891 Change-Id: I37e2f7429c23046f5dbf729d8a9a9e0b9b074202 Signed-off-by: Michael Vorburger <vorburger@redhat.com>
|
What version of Error Prone are you using?
2.1.3
Does this issue reproduce with the latest release?
yes (as 2.1.3 seems to be the latest release)
What did you do?
Following #723, I enabled the
ReturnMissingNullable
check on an existing code base (OpenDaylight) on which I had experimented with the Eclipse JDT based null analysis (see also http://www.lastnpe.org), and have hit this:The method was annotated with
org.eclipse.jdt.annotation.Nullable
instead ofjavax.annotation.Nullable
. (If required, I could provide a recipe or a complete small program for reproducing the error, but it should hopefully be obvious what I mean.)Would you guys consider accepting other annotations for your null analysis? Either by configuration of all accepted FQNs, or perhaps even through some pragmatic solution like "just look only at the name not the FQN with package, and accept anyhing named Nullable goes, unrelated to the package". (AFAIK some other thing does this as well - I can't remember if its SpotBugs (ex FindBugs) or IntelliJ or what; FYI e.g. in Eclipse there is a Preference to set a list of FQNs.)
Obviously this isn't only about Nullable but all typically 3 null related annotations (Nullable, NonNull and NonNullByDefault).
I may be motivated to contributed a PR for this later if I hit this problem more often, if there is interest for doing something about this - just filing this to gauge the maintainers initial reaction and position about this.
PS: Note the problem is of course not really directly related to lastnpe.org Eclipse JDT based null analysis - if one were to prefer using say e.g. the
org.checkerframework.checker.nullness.qual.Nullable
from the Checker Framework, then one would most likely hit exactly the same problem. Some people use their own internal null related annotations instead of any public one, and then customizes tools to use those. Long story short: IMHO a tool such as error-prone, in an ideal world, should be open to accepting different types of null annotations.PPS: Please note that JSR 305 null analysis related annotations in the javax.annotation package are by no means "standard" or the only ones - there are, clearly, other such annotations out there - including in Google's own Android AFAIK. Also the old JSR 305 are not Java 8 Type annotations yet, but e.g. Eclipse' and Checker Framework's are.
The text was updated successfully, but these errors were encountered: