-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Proposal: Switch to a provided JSR305 artifact for nullability + package annotations #5341
Comments
I'd also prefer if RxJava would use the JSR305 |
stable, but not a breaking API change technically (from a compile perspective) since they're just annotations and the new annotations would be a superset of their functionality. They could be left in if the idea was to allow other RxJava-dependent libraries to use them if they want, while RxJava itself could use JSR305? |
If you specify I suppose provided is an acceptable option but can't delete our own annotation files; at most we strip them from all those paces which should still count as binary compatible. |
You'd mark it as |
That's not the same as not defining it. Wouldn't an IDE complain about not checking for null for both parameters when you know only one of them can be null with that specific |
Yup that will be a drawback. Once |
Are there many other cases like that? |
Any |
Let's see the implications in a PR. Remember, don't delete the original RxJava annotation files. |
Anybody still interested in adding the annotations? Note though that due to the bad interaction of JSR305 and Java 9, we should stick to our own annotations which are supposedly understood by IntelliJ. |
I just regularly review code where nullable things are accidentially returned from |
JSR 305 is dead and actively prevents libraries from being used on the module path with Java 9 and newer. We should be tearing it out of every library which made the mistake of adding it. |
I see, just found some context: https://blog.codefx.org/java/jsr-305-java-9/ |
And I'm not specifically against what you proposed, just JSR 305 in general. Your comment just reminded me of this issue being a thing. |
Closing because of JSR 305's problem with modules in 9. We'll keep using our own annotations and apply it wherever necessary. |
In case it interests you, I wrote a blog post about when it still makes sense to use JSR 305 instead of e.g. Checker Framework, provided that you have the requirements I had. In short, JSR 305 is the only library whose package-scope annotations are honored by both IntelliJ and Kotlin. Also, note that JSR 305 can be used with JPMS - it just needs to be patched if there's a conflict. |
I'd like to propose switching away from the current custom
@Nullable
and@NonNull
annotations and using a combination of a provided JSR305 dependency (that is, onlycompileOnly
and not actually packaged, but still visible to static analysis tools).This would provide two main benefits:
@Nullable
annotation (Guava uses the same one). Currently anyone that uses other annotations gets burdened with fully-qualified copies of RxJava's due to IDE autocomplete, and it's a nuisance to clean it up.@NonNull
. You could use@ParametersAreNonnullByDefault
for just parameters, or also have a separate artifact with a custom@EverythingIsNonNullByDefault
annotation like here that would also cover fields and return types. This would obviate the need for using@NonNull
entirely, and is respected by most conventional static analysis tools.I know RxJava prefers to have no dependencies, but I think that having this as a provided dependency is a good middle ground for the value it provides.
Other prior reading:
The text was updated successfully, but these errors were encountered: