fb-contrib icon indicating copy to clipboard operation
fb-contrib copied to clipboard

AI_ANNOTATION_ISSUES_NEEDS_NULLABLE support JSpecify out-of-the-box

Open sdavids opened this issue 1 year ago • 1 comments

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]

sdavids avatar Aug 26 '24 18:08 sdavids

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

ThrawnCA avatar Sep 06 '24 03:09 ThrawnCA

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.

sdavids avatar Sep 06 '24 07:09 sdavids

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.

ThrawnCA avatar Sep 11 '24 23:09 ThrawnCA

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

sdavids avatar Sep 20 '24 16:09 sdavids

This has not been fixed in 7.6.5.

$ 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.5
$ 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]

sdavids avatar Oct 01 '24 16:10 sdavids

Also, I cannot find a changelog, release notes or GitHub releases?!?

This one stops at 7.4.0.

sdavids avatar Oct 01 '24 16:10 sdavids

https://github.com/spring-projects/spring-framework/issues/28797#issuecomment-2387137015

sdavids avatar Oct 01 '24 22:10 sdavids

I tried to verify if this issue has been fixed with 7.6.6 but I stumbled upon a different issue: #476

sdavids avatar Nov 04 '24 18:11 sdavids

This has not been fixed in 7.6.6 either.

$ 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.6
$ 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/sb-contrib/sb-contrib/$SB_CONTRIB_VERSION/sb-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]

I am not sure what has been done but this issue should be reopened…

sdavids avatar Nov 05 '24 15:11 sdavids

This has not been fixed in 7.6.8 either.

$ mkdir -p /tmp/test/example/test && cd "$_/../.."
$ echo 'java=21.0.5-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.8
$ 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/sb-contrib/sb-contrib/$SB_CONTRIB_VERSION/sb-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]

sdavids avatar Dec 06 '24 14:12 sdavids