Attempting to add spot bugs to Apache Cassandra but fails with “Resource not found: java/lang/Object.class” on Java 8
dcapwell opened this issue · comments
I am trying to add the spotbug-ant task to Apache Cassandra but I am getting the following error
[spotbugs] java.io.IOException: IOException while scanning codebases
[spotbugs] at edu.umd.cs.findbugs.FindBugs2.execute(FindBugs2.java:311)
[spotbugs] at edu.umd.cs.findbugs.FindBugs.runMain(FindBugs.java:395)
[spotbugs] at edu.umd.cs.findbugs.FindBugs2.main(FindBugs2.java:1231)
[spotbugs] Caused by: edu.umd.cs.findbugs.classfile.ResourceNotFoundException: Resource not found: java/lang/Object.class
[spotbugs] at edu.umd.cs.findbugs.classfile.impl.ClassPathImpl.lookupResource(ClassPathImpl.java:162)
[spotbugs] at edu.umd.cs.findbugs.classfile.impl.ClassPathBuilder.build(ClassPathBuilder.java:282)
[spotbugs] at edu.umd.cs.findbugs.FindBugs2.buildClassPath(FindBugs2.java:708)
[spotbugs] at edu.umd.cs.findbugs.FindBugs2.execute(FindBugs2.java:245)
[spotbugs] ... 2 more
[spotbugs] Java Result: 4
I can confirm this is running java 8 as I see that in the error
spotbugs:
[spotbugs] Executing SpotBugs FindBugsTask from ant task
[spotbugs] Running SpotBugs...
[spotbugs] Executing '/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/jre/bin/java' with arguments:
[spotbugs] '-Dfindbugs.debug=true'
[spotbugs] '-Dfindbugs.hostApp=FBAntTask'
[spotbugs] '-classpath'
[spotbugs] ‘<trimmed as this is long>
[spotbugs] 'edu.umd.cs.findbugs.FindBugs2'
[spotbugs] '-timestampNow'
[spotbugs] '-xml'
[spotbugs] '-exitcode’
I have found #148 but this looks to be a JDK 9+ issue and I am failing with JDK 8.
Here is my ant file
<target name="init-spotbugs" depends="resolver-retrieve-build,build-project" unless="no-spotbugs">
<path id="spotbugs.lib.path">
<fileset dir="${test.lib}/jars" includes="*.jar"/>
</path>
<taskdef resource="edu/umd/cs/findbugs/anttask/tasks.properties"
classpathref="spotbugs.lib.path" />
</target>
<condition property="_spotbugs_jvm_args" value="" else="--add-modules=ALL-SYSTEM">
<equals arg1="${ant.java.version}" arg2="1.8" />
</condition>
<target name="spotbugs" depends="init-spotbugs" description="Run SpotBugs code analysis" unless="no-spotbugs">
<!-- TODO do we add if="java.version.8"? Validate JDK11 -->
<spotbugs classpathref="spotbugs.lib.path" debug="true" jvmargs="${_spotbugs_jvm_args}">
<fileset dir="${build.src.java}" includes="**/*.java"/>
</spotbugs>
</target>
The spotbug-ant used is
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-ant</artifactId>
<version>4.7.3</version>
<scope>test</scope>
</dependency>
Running on M1 Mac (arm)
Thanks for opening your first issue here! 😃
Please check our contributing guideline. Especially when you report a problem, make sure you share a Minimal, Complete, and Verifiable example to reproduce it in this issue.
Tested on jdk11 and see the same issue, on JDK 11 i made sure to include --add-modules=ALL-SYSTEM
and see it in the debug output
I copied the output into a script to help isolate the issue and tried adding /Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/jre/lib/rt.jar
to the classpath just in case... still no luck....
tried adding '-auxclasspath' '/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/jre/lib/rt.jar'
but that seems to fail differently now
0 classes scanned
Adding referenced classes
Added 0 referenced classes
Total of 0 packages
Adding plugin edu.umd.cs.findbugs.plugins.core to execution plan
Dependences force enabling of edu.umd.cs.findbugs.detect.NoteNonnullReturnValues
2 passes in execution plan
java.io.IOException: No files to analyze could be opened
at edu.umd.cs.findbugs.FindBugs2.execute(FindBugs2.java:302)
at edu.umd.cs.findbugs.FindBugs.runMain(FindBugs.java:395)
at edu.umd.cs.findbugs.FindBugs2.main(FindBugs2.java:1231)
https://spotbugs.readthedocs.io/en/latest/ant.html. Docs also don't see accurate...
switched to <sourcePath path="${build.src.java}" />
thinking this might be somehow related to the use of fileset
and now fails validation
spotbugs:
BUILD FAILED
/Users/dcapwell/src/github/apache/cassandra/trunk/build.xml:1904: either projectfile, <class/>, <fileset/> or <auxAnalyzepath/> child elements must be defined for task <spotbugs/>
Ok i finally got this working! I had to tell spotbugs to use the compiled code found in the jar...
<class location="${build.dir}/${final.name}.jar" />
Giving it source files seems to fail outright, but the compiled jar works...
closing as resolved per user.