Closed xenoterracide closed 5 months ago
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
</dependency>
Do you have jsr305-3.0.2.jar
in the class path or module path?
it appears you can't use
jsr305
as the automatic module name.
What happens when you attempt to do that?
Are you encountering issues with split packages?
I've also getting this, but adding jsr305
worked.
I wonder why it is not working as it was available as a transitive dependency
in the classpath
, but working fine after adding it as 'direct dependency`. Any one please share some views on it.
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 jsr305
in the classpath or module path.
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 jsr305
to the transitive dependencies in a mandatory way.
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...
...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.
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:
@Nullable
or @CheckForNull
. (Of course, it's nice for the average user not to have to.) And they even might recognize any annotations with those simple class names, as tools like NullAway do.@NonNullApi
, probably do require the JSR-305 annotations in order to work in IntelliJ and SpotBugs, possibly in contrast to simple @Nullable
and @NonNull
annotations.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:
unknown enum constant When.MAYBE
compilation warningsI had sadly to revert the related commit as, as observed by @jhoeller, IntelliJ IDEA is not able to recognize @Nullable
semantics with that change.
@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 @Nullable
instead of @CheckForNull
, but it looks like it does not. (I'm actually not surprised by that: The JSR-305 @Nullable
technically is more like "unknown nullness" than it is what people normally mean by "nullable." I don't remember offhand if Kotlin behaves the same way.)
I've filed IDEA-351380 to see if we can get support for @TypeQualifierNickname @CheckForNull
. Star, vote, etc. :)
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.