Findbugs reports this:
findbugs:
[findbugs] Executing findbugs from ant task
[findbugs] Running FindBugs...
[findbugs] The following classes needed for analysis were missing:
[findbugs] com.company.OptionalClass
[findbugs] Warnings generated: 11
[findbugs] Missing classes: 2
[findbugs] Calculating exit code...
[findbugs] Setting 'missing class' flag (2)
[findbugs] Setting 'bugs found' flag (1)
[findbugs] Exit code set to: 3
[findbugs] Java Result: 3
[findbugs] Classes needed for analysis were missing
[findbugs] Output saved to findbugs.xml
BUILD SUCCESSFUL
This OptionalClass is referenced from a third-party jar for which I do not have the source code, and for which I do not want a findbugs analysis. It refers to a class I do not have in my classpath, or anywhere else. This class is probably used in certain cases, when our third-party jar is configured in a certain way.
Is there a way to tell findbugs to ignore this class?
Note that it completes the analysis and produces a findbugs.xml
report, so this is a minor issue.
FindBugs is an open-source static code analyser created by Bill Pugh and David Hovemeyer which detects possible bugs in Java programs. Potential errors are classified in four ranks: (i) scariest, (ii) scary, (iii) troubling and (iv) of concern. This is a hint to the developer about their possible impact or severity.
To suppress violations you can use filter file. In this case you need to override default filter file. Spotbugs can't use default @SuppressWarnings annotation because it's a source annotation and not available in bytecode.
The preferred method of running FindBugs is to directly execute $FINDBUGS_HOME /lib/findbugs. jar using the -jar command line switch of the JVM (java) executable. (Versions of FindBugs prior to 1.3. 5 required a wrapper script to invoke FindBugs.)
This message appears because somewhere in your binary classes you are referencing that class. It does not necessarily mean that FindBugs was trying to analyse com.company.OptionalClass
to report on it; rather it is more likely FindBugs was analysing it to get more information about the class which references it.
Consider some of your source code, which you do want analysed:
package my.actual.codebase;
import com.some.third.party.stuff.OptionalClass;
class ReferencesOptionalClass extends OptionalClass {}
This kind of example is common with test classes, which reference e.g. org.junit.@Test
but the JUnit jar is not included in what you want to analyse.
In the above example you do want results for ReferenceOptionalClass
, but in order to get them, some parts of FindBugs need to look at OptionalClass
. If it can't do that, because it's not there, it reports that the class is missing[1]. When FindBugs can't find that class, it generally just aborts the specific kind of analysis it was trying to do, and carries on with the rest of the analysis without problem.
The simple answer is if you are happy with the level of analysis FindBugs is giving you, then just ignore the error.
[1] Note that it's likely that this could even be a transitive reference i.e. your code includes class A, which references B in an auxiliary JAR, which then references OptionalClass.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With