-
Notifications
You must be signed in to change notification settings - Fork 38.2k
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
Replace @Nonnull(when = When.MAYBE)
by @CheckForNull
in @Nullable
#27183
Comments
|
Do you have
What happens when you attempt to do that? Are you encountering issues with split packages? |
I've also getting this, but adding I wonder why it is not working as it was available as a |
This is a known side effect of current JSR 305 support, the Java compiler generates warning on annotation with enum values when not present in the classpath while it is lenient for the annotations themselves. As suggested by Sam, the workaround is to have the If I am not mistaken, this only occurs when user code is using Spring null-safety annotations, so that's on purpose that we don't add The middle term fix will be to switch to https://github.com/jspecify/jspecify (where Spring team is involved) and remove those JSR305 annotations from Spring ones. @sbrannen What about creating an issue dedicated to switching from JSR 305 to JSpecify in the 6.x Backlog in order to give visibility to our users and closing this one? |
|
I am all in favor of a migration to JSpecify, but FYI, I suspect that you can prevent this warning by changing... spring-framework/spring-core/src/main/java/org/springframework/lang/Nullable.java Line 53 in 6f95af9
...to just... @CheckForNull We do this for a common annotation inside Google, and it works well with Kotlin. |
Thanks for the insight, I am going to give it a try. |
@Nonnull(when = When.MAYBE)
by @CheckForNull
in @Nullable
curious, what problem does using meta annotations actually solve in todays world? how is that consumed? most tools that would have used it now support these things just by looking at Nonnull/Nullable, I think. |
I think that the tool that people usually care most about is Kotlin:
The meta annotations are also supported by IntelliJ when editing Java code. And I assume that SpotBugs has inherited FindBugs's support for them. I'd be interested in knowing of other tools that are of interest to people, too. |
Yes, but spotbugs and IntelliJ also support not having those specific meta annotations. Other annotations work now. Unless you know something that I don't about how those tools work. Which is quite possible. I guess I'm just questioning on whether or not there's any tooling that requires those annotations or any part of those toolings that require those meta annotations. There's a lot of nullity annotations out there right now that don't have the meta annotations. So a lot of tools are supporting without, I believe. It's probably worth saying that my primary nullness checker is errorprone null away. Checker framework is also pretty popular. I think it might be worth testing the assumption that these meta annotations are still really buying you anything at all. |
I suspect that they don't buy a ton except for Kotlin. I'd have to look into IntelliJ and SpotBugs:
|
Fair, I was just suggesting verifying that the world is still needing this for something. Uh, If you see that very inappropriate thing show up in an email... I was speech to texting and Google translated something from my TV. Sorry I honestly want you to know I didn't say that. |
Seems to work as expected based on my tests:
|
I had sadly to revert the related commit as, as observed by @jhoeller, IntelliJ IDEA is not able to recognize @cpovirk Let's maybe discuss that with JetBrains. |
Oh, that's a shame :( Thanks for letting me know. I may try to switch the one we're using in Google now. I wondered if maybe IntelliJ would do what we want if we were to use I've filed IDEA-351380 to see if we can get support for |
According to https://youtrack.jetbrains.com/issue/IDEA-351380/Support-CheckForNull-with-TypeQualifierNickname seems that IDE's behavior is fixed in IntelliJ IDEA 2024.1.2 |
it appears this is found in the findbugs jsr305 annotations my reason why is I want to enable
-Werror
and I'm using java modulesmodule-info.java
and it appears you can't usejsr305
as the automatic module name. sadly I don't actually know whatWhen
does or if there's a replacement. most tools seem to respect annotations namedNullable
orNonNull
now.The text was updated successfully, but these errors were encountered: