Skip to content
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

AI_ANNOTATION_ISSUES_NEEDS_NULLABLE support JSpecify out-of-the-box #473

Open
sdavids opened this issue Aug 26, 2024 · 4 comments
Open

AI_ANNOTATION_ISSUES_NEEDS_NULLABLE support JSpecify out-of-the-box #473

sdavids opened this issue Aug 26, 2024 · 4 comments

Comments

@sdavids
Copy link

sdavids commented Aug 26, 2024

JSpecify - What is this

org.jspecify.annotations.Nullable

$ mkdir -p /tmp/test/example/test && cd "$_/../.."
$ echo 'java=21.0.4-tem' > .sdkmanrc && sdk env
$ printf 'package test;\nimport org.jspecify.annotations.Nullable;\nclass Test {\n  @Nullable Object get() {\n    return null;\n  }\n}\n' > example/Test.java
$ cat example/Test.java
package test;
import org.jspecify.annotations.Nullable;
class Test {
  @Nullable Object get() {
    return null;
  }
}
$ JSPECIFY_VERSION=1.0.0
$ curl -L -O -s https://repo1.maven.org/maven2/org/jspecify/jspecify/$JSPECIFY_VERSION/jspecify-$JSPECIFY_VERSION.jar
$ javac -cp jspecify-$JSPECIFY_VERSION.jar example/Test.java
$ SPOTBUGS_VERSION=4.8.6
$ SB_CONTRIB_VERSION=7.6.4
$ curl -L -O -s https://github.com/spotbugs/spotbugs/releases/download/$SPOTBUGS_VERSION/spotbugs-$SPOTBUGS_VERSION.tgz
$ tar -xzf spotbugs-$SPOTBUGS_VERSION.tgz && rm spotbugs-$SPOTBUGS_VERSION.tgz
$ SPOTBUGS_HOME=spotbugs-$SPOTBUGS_VERSION
$ curl -L -O -s --output-dir $SPOTBUGS_HOME/plugin https://repo1.maven.org/maven2/com/mebigfatguy/fb-contrib/fb-contrib/$SB_CONTRIB_VERSION/fb-contrib-$SB_CONTRIB_VERSION.jar
$ java -jar $SPOTBUGS_HOME/lib/spotbugs.jar -textui -sourcepath example -auxclasspath=./jspecify-$JSPECIFY_VERSION.jar -effort:max -low -longBugCodes example
L C AI_ANNOTATION_ISSUES_NEEDS_NULLABLE AI: Method test.Test.get() that can return null, is missing a @Nullable annotation  At Test.java:[line 5]
@ThrawnCA
Copy link
Contributor

ThrawnCA commented Sep 6, 2024

I don't understand what your issue is just by reading the description. Can you add more detail?

@sdavids
Copy link
Author

sdavids commented Sep 6, 2024

AI_ANNOTATION_ISSUES_NEEDS_NULLABLE does not support the JSpecify annotations.

Using them errors out with:

L C AI_ANNOTATION_ISSUES_NEEDS_NULLABLE AI: Method test.Test.get() that can return null, is missing a @Nullable annotation At Test.java:[line 5]

See the reproducer above.

Yes, one could add them as custom annotations (-Dfb-contrib.ai.annotations) but hopefully they are the way forward in the annotation mess—therefore it makes sense to support them out-of-the-box, i.e. using them does not lead to errors.

@ThrawnCA
Copy link
Contributor

Yes, one could add them as custom annotations (-Dfb-contrib.ai.annotations) but hopefully they are the way forward in the annotation mess—therefore it makes sense to support them out-of-the-box, i.e. using them does not lead to errors.

:D Nice optimism you have there. Shame if something happened to it...

If and when a standard actually becomes the standard, then it makes sense to support it out-of-the-box.

@sdavids
Copy link
Author

sdavids commented Sep 20, 2024

Who is involved:

https://jspecify.dev/about/

So basically every major party involved with Nullness-checking besides FindBugs/SpotBugs.

Yes, it is led by Google and their spectacular track record.

And yes, I am aware of the relationship JSR304 ⇔ William Pugh ⇔ FindBugs.

If and when a standard actually becomes the standard, then it makes sense to support it out-of-the-box.

There will never be the standard unless it is part of the Java Spec which most likely never happens in our lifetime 😉

The less tools support the JSpecify effort, the more likely it is that we are stuck with JSR 305 and everybody doing their own thing™—which we have for 18 years; made worse by the Java 9 javax.annotation split package challenge.


AI_ANNOTATION_ISSUES_NEEDS_NULLABLE [...] but this detector will recognize:

org.jetbrains.annotations.Nullable <1>

javax.annotation.Nullable <2>

javax.annotation.CheckForNull <2>

edu.umd.cs.findbugs.annotations.Nullable

org.springframework.lang.Nullable <1>

android.support.annotations.Nullable <1>

<1> corresponding organization participates in JSpecify effort

<2> JSR working group is non-existent


Other adopters:

https://kotlinlang.org/docs/whatsnew1520.html#support-for-jspecify-nullness-annotations

https://docs.openrewrite.org/recipes/java/jspecify

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@sdavids @ThrawnCA and others