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.

3 Answers
3

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.

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.

To ignore the third-party classes, specify an option -auxclasspath classpath when using command-line or provide an nested element <auxClasspath refid="classpath"> when using ant task, where your third-party jar is in the classpath.