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
157 stars 45 forks source link

7.6.6 regression - DetectorFactoryCollection: ExceptionInInitializerError #476

Closed sdavids closed 1 week ago

sdavids commented 2 weeks ago
$ 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/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/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/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
Exception in thread "main" java.lang.ExceptionInInitializerError
    at edu.umd.cs.findbugs.DetectorFactoryCollection.getCoreResource(DetectorFactoryCollection.java:353)
    at edu.umd.cs.findbugs.SystemProperties.loadPropertiesFromConfigFile(SystemProperties.java:84)
    at edu.umd.cs.findbugs.SystemProperties.<clinit>(SystemProperties.java:67)
    at edu.umd.cs.findbugs.FindBugs2.<clinit>(FindBugs2.java:98)
    at edu.umd.cs.findbugs.LaunchAppropriateUI.launch(LaunchAppropriateUI.java:106)
    at edu.umd.cs.findbugs.LaunchAppropriateUI.main(LaunchAppropriateUI.java:198)
Caused by: java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "this.classLoader" is null
    at edu.umd.cs.findbugs.PluginLoader.getPluginDescriptor(PluginLoader.java:1194)
    at edu.umd.cs.findbugs.PluginLoader.init(PluginLoader.java:737)
    at edu.umd.cs.findbugs.PluginLoader.<init>(PluginLoader.java:210)
    at edu.umd.cs.findbugs.PluginLoader.getPluginLoader(PluginLoader.java:1378)
    at edu.umd.cs.findbugs.PluginLoader.loadInitialPlugin(PluginLoader.java:1500)
    at edu.umd.cs.findbugs.PluginLoader.loadPluginsInDir(PluginLoader.java:1430)
    at edu.umd.cs.findbugs.PluginLoader.loadPlugins(PluginLoader.java:1405)
    at edu.umd.cs.findbugs.PluginLoader.installStandardPlugins(PluginLoader.java:1400)
    at edu.umd.cs.findbugs.PluginLoader.loadInitialPlugins(PluginLoader.java:1448)
    at edu.umd.cs.findbugs.PluginLoader.<clinit>(PluginLoader.java:153)
    ... 6 more

Downgrading to 7.6.5 will remove the exception:

$ rm $SPOTBUGS_HOME/plugin/fb-contrib-7.6.6.jar
$ SB_CONTRIB_VERSION=7.6.5
$ 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]
mebigfatguy commented 2 weeks ago

anyone else seeing this?... i'm not.

sdavids commented 2 weeks ago
$ mkdir -p /tmp/test && cd "$_"
$ cat <<'EOF' >Dockerfile
FROM eclipse-temurin:21.0.4_7-jdk-jammy

ENV JSPECIFY_VERSION=1.0.0

ENV SPOTBUGS_VERSION=4.8.6

ENV SB_CONTRIB_VERSION=7.6.6

ENV SPOTBUGS_HOME=spotbugs-$SPOTBUGS_VERSION

RUN curl -L -O -s https://repo1.maven.org/maven2/org/jspecify/jspecify/$JSPECIFY_VERSION/jspecify-$JSPECIFY_VERSION.jar

RUN curl -L -O -s https://github.com/spotbugs/spotbugs/releases/download/$SPOTBUGS_VERSION/spotbugs-$SPOTBUGS_VERSION.tgz

RUN tar -xzf spotbugs-$SPOTBUGS_VERSION.tgz && rm spotbugs-$SPOTBUGS_VERSION.tgz

RUN 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

RUN mkdir -p example/test

RUN printf 'package test;\nimport org.jspecify.annotations.Nullable;\nclass Test {\n  @Nullable Object get() {\n    return null;\n  }\n}\n' > example/test/Test.java

RUN javac -cp jspecify-$JSPECIFY_VERSION.jar example/test/Test.java

RUN java -jar $SPOTBUGS_HOME/lib/spotbugs.jar -textui -sourcepath example -auxclasspath=./jspecify-$JSPECIFY_VERSION.jar -effort:max -low -longBugCodes example
EOF
$ docker build --progress=plain .
...
#12 [9/9] RUN java -jar spotbugs-4.8.6/lib/spotbugs.jar -textui -sourcepath example -auxclasspath=./jspecify-1.0.0.jar -effort:max -low -longBugCodes example
#12 0.689 Exception in thread "main" java.lang.ExceptionInInitializerError
#12 0.689   at edu.umd.cs.findbugs.DetectorFactoryCollection.getCoreResource(DetectorFactoryCollection.java:353)
#12 0.689   at edu.umd.cs.findbugs.SystemProperties.loadPropertiesFromConfigFile(SystemProperties.java:84)
#12 0.689   at edu.umd.cs.findbugs.SystemProperties.<clinit>(SystemProperties.java:67)
#12 0.689   at edu.umd.cs.findbugs.FindBugs2.<clinit>(FindBugs2.java:98)
#12 0.689   at edu.umd.cs.findbugs.LaunchAppropriateUI.launch(LaunchAppropriateUI.java:106)
#12 0.689   at edu.umd.cs.findbugs.LaunchAppropriateUI.main(LaunchAppropriateUI.java:198)
#12 0.689 Caused by: java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "this.classLoader" is null
#12 0.690   at edu.umd.cs.findbugs.PluginLoader.getPluginDescriptor(PluginLoader.java:1194)
#12 0.690   at edu.umd.cs.findbugs.PluginLoader.init(PluginLoader.java:737)
#12 0.690   at edu.umd.cs.findbugs.PluginLoader.<init>(PluginLoader.java:210)
#12 0.690   at edu.umd.cs.findbugs.PluginLoader.getPluginLoader(PluginLoader.java:1378)
#12 0.690   at edu.umd.cs.findbugs.PluginLoader.loadInitialPlugin(PluginLoader.java:1500)
#12 0.690   at edu.umd.cs.findbugs.PluginLoader.loadPluginsInDir(PluginLoader.java:1430)
#12 0.690   at edu.umd.cs.findbugs.PluginLoader.loadPlugins(PluginLoader.java:1405)
#12 0.690   at edu.umd.cs.findbugs.PluginLoader.installStandardPlugins(PluginLoader.java:1400)
#12 0.690   at edu.umd.cs.findbugs.PluginLoader.loadInitialPlugins(PluginLoader.java:1448)
#12 0.690   at edu.umd.cs.findbugs.PluginLoader.<clinit>(PluginLoader.java:153)
#12 0.690   ... 6 more
#12 ERROR: process "/bin/sh -c java -jar $SPOTBUGS_HOME/lib/spotbugs.jar -textui -sourcepath example -auxclasspath=./jspecify-$JSPECIFY_VERSION.jar -effort:max -low -longBugCodes example" did not complete successfully: exit code: 1
------
 > [9/9] RUN java -jar spotbugs-4.8.6/lib/spotbugs.jar -textui -sourcepath example -auxclasspath=./jspecify-1.0.0.jar -effort:max -low -longBugCodes example:
0.690   at edu.umd.cs.findbugs.PluginLoader.init(PluginLoader.java:737)
0.690   at edu.umd.cs.findbugs.PluginLoader.<init>(PluginLoader.java:210)
0.690   at edu.umd.cs.findbugs.PluginLoader.getPluginLoader(PluginLoader.java:1378)
0.690   at edu.umd.cs.findbugs.PluginLoader.loadInitialPlugin(PluginLoader.java:1500)
0.690   at edu.umd.cs.findbugs.PluginLoader.loadPluginsInDir(PluginLoader.java:1430)
0.690   at edu.umd.cs.findbugs.PluginLoader.loadPlugins(PluginLoader.java:1405)
0.690   at edu.umd.cs.findbugs.PluginLoader.installStandardPlugins(PluginLoader.java:1400)
0.690   at edu.umd.cs.findbugs.PluginLoader.loadInitialPlugins(PluginLoader.java:1448)
0.690   at edu.umd.cs.findbugs.PluginLoader.<clinit>(PluginLoader.java:153)
0.690   ... 6 more
------
Dockerfile:25
...
mebigfatguy commented 2 weeks ago

oh, i think this is the problem, looking at the output of docker build

https://repo1.maven.org/maven2/com/mebigfatguy/fb-contrib/fb-contrib/$SB_CONTRIB_VERSION/fb-contrib-$SB_CONTRIB_VERSION.jar

you want

https://repo1.maven.org/maven2/com/mebigfatguy/sb-contrib/sb-contrib/$SB_CONTRIB_VERSION/sb-contrib-$SB_CONTRIB_VERSION.jar

sdavids commented 2 weeks ago

OK, I checked it.

I would still say it is regression though:

With version 7.6.5 it (using fb-contrib-7.6.5.jar with SpotBugs) works, with version 7.6.6 it does not.

It is a behavioural change even if it was unintentional behaviour—that is not something one expects in a patch release.

$ mkdir -p /tmp/test && cd "$_"
$ cat <<'EOF' >Dockerfile
FROM eclipse-temurin:21.0.4_7-jdk-jammy

ENV JSPECIFY_VERSION=1.0.0

ENV SPOTBUGS_VERSION=4.8.6

ENV SB_CONTRIB_VERSION=7.6.6

ENV SPOTBUGS_HOME=spotbugs-$SPOTBUGS_VERSION

RUN curl -L -O -s https://repo1.maven.org/maven2/org/jspecify/jspecify/$JSPECIFY_VERSION/jspecify-$JSPECIFY_VERSION.jar

RUN curl -L -O -s https://github.com/spotbugs/spotbugs/releases/download/$SPOTBUGS_VERSION/spotbugs-$SPOTBUGS_VERSION.tgz

RUN tar -xzf spotbugs-$SPOTBUGS_VERSION.tgz && rm spotbugs-$SPOTBUGS_VERSION.tgz

RUN 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

RUN mkdir -p example/test

RUN printf 'package test;\nimport org.jspecify.annotations.Nullable;\nclass Test {\n  @Nullable Object get() {\n    return null;\n  }\n}\n' > example/test/Test.java

RUN javac -cp jspecify-$JSPECIFY_VERSION.jar example/test/Test.java

RUN java -jar $SPOTBUGS_HOME/lib/spotbugs.jar -textui -sourcepath example -auxclasspath=./jspecify-$JSPECIFY_VERSION.jar -effort:max -low -longBugCodes example
EOF
$ docker build --progress=plain --no-cache .
...
#12 [9/9] RUN java -jar spotbugs-4.8.6/lib/spotbugs.jar -textui -sourcepath example -auxclasspath=./jspecify-1.0.0.jar -effort:max -low -longBugCodes example
#12 0.689 Exception in thread "main" java.lang.ExceptionInInitializerError
...
$ cat <<'EOF' >Dockerfile
FROM eclipse-temurin:21.0.4_7-jdk-jammy

ENV JSPECIFY_VERSION=1.0.0

ENV SPOTBUGS_VERSION=4.8.6

ENV SB_CONTRIB_VERSION=7.6.5

ENV SPOTBUGS_HOME=spotbugs-$SPOTBUGS_VERSION

RUN curl -L -O -s https://repo1.maven.org/maven2/org/jspecify/jspecify/$JSPECIFY_VERSION/jspecify-$JSPECIFY_VERSION.jar

RUN curl -L -O -s https://github.com/spotbugs/spotbugs/releases/download/$SPOTBUGS_VERSION/spotbugs-$SPOTBUGS_VERSION.tgz

RUN tar -xzf spotbugs-$SPOTBUGS_VERSION.tgz && rm spotbugs-$SPOTBUGS_VERSION.tgz

RUN 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

RUN mkdir -p example/test

RUN printf 'package test;\nimport org.jspecify.annotations.Nullable;\nclass Test {\n  @Nullable Object get() {\n    return null;\n  }\n}\n' > example/test/Test.java

RUN javac -cp jspecify-$JSPECIFY_VERSION.jar example/test/Test.java

RUN java -jar $SPOTBUGS_HOME/lib/spotbugs.jar -textui -sourcepath example -auxclasspath=./jspecify-$JSPECIFY_VERSION.jar -effort:max -low -longBugCodes example
EOF
$ docker build --progress=plain --no-cache .
...
#12 [9/9] RUN java -jar spotbugs-4.8.6/lib/spotbugs.jar -textui -sourcepath example -auxclasspath=./jspecify-1.0.0.jar -effort:max -low -longBugCodes example
#12 1.610 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]
#12 DONE 1.7s
...
$ cat <<'EOF' >Dockerfile
FROM eclipse-temurin:21.0.4_7-jdk-jammy

ENV JSPECIFY_VERSION=1.0.0

ENV SPOTBUGS_VERSION=4.8.6

ENV SB_CONTRIB_VERSION=7.6.6

ENV SPOTBUGS_HOME=spotbugs-$SPOTBUGS_VERSION

RUN curl -L -O -s https://repo1.maven.org/maven2/org/jspecify/jspecify/$JSPECIFY_VERSION/jspecify-$JSPECIFY_VERSION.jar

RUN curl -L -O -s https://github.com/spotbugs/spotbugs/releases/download/$SPOTBUGS_VERSION/spotbugs-$SPOTBUGS_VERSION.tgz

RUN tar -xzf spotbugs-$SPOTBUGS_VERSION.tgz && rm spotbugs-$SPOTBUGS_VERSION.tgz

RUN 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

RUN mkdir -p example/test

RUN printf 'package test;\nimport org.jspecify.annotations.Nullable;\nclass Test {\n  @Nullable Object get() {\n    return null;\n  }\n}\n' > example/test/Test.java

RUN javac -cp jspecify-$JSPECIFY_VERSION.jar example/test/Test.java

RUN java -jar $SPOTBUGS_HOME/lib/spotbugs.jar -textui -sourcepath example -auxclasspath=./jspecify-$JSPECIFY_VERSION.jar -effort:max -low -longBugCodes example
EOF
$ docker build --progress=plain --no-cache .
...
#12 [9/9] RUN java -jar spotbugs-4.8.6/lib/spotbugs.jar -textui -sourcepath example -auxclasspath=./jspecify-1.0.0.jar -effort:max -low -longBugCodes example
#12 1.550 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]
#12 DONE 1.6s
...
mebigfatguy commented 2 weeks ago

i wouldn't expect 7.6.5 fb to work with spotbugs. Not sure why that would happen.