mebigfatguy / fb-contrib

a FindBugs/SpotBugs plugin for doing static code analysis for java code bases
http://fb-contrib.sf.net
GNU Lesser General Public License v2.1
153 stars 45 forks source link

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

Open sdavids opened 3 weeks ago

sdavids commented 3 weeks ago

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 commented 1 week ago

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

sdavids commented 1 week ago

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 commented 6 days ago

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.