tags:

views:

104

answers:

2

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.

+1  A: 

No, But you do not need source or to generate findbugs reports for this code if you add the jar to the 'auxillary jars' section of the findbugs project file.

MeBigFatGuy
I do not have the jar of compiled classes either.
Nicolas Marchildon
+1  A: 

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.

Grundlefleck