1

I installed findbugs into my ant lib directory and added the following code into my main ANT script:

<target name="findbugs" depends="init">

    <findbugs home="C:\\findbugs\\" output="html outputFile="C:\\findbugs\\out.html" jvmargs="-Xms512M">
        <sourcePath path="${messageaggregator.src}" />
        <class location="${messageaggregator.src}"/>


    </findbugs>
</target>

The following xml is called within the init target:

<taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask">

On running the ANT script, all I get is the following output:

findbugs:
    [findbugs] Executing findbugs from ant task
    [findbugs] Running FindBugs...
    [findbugs] BCEL class compatability error.
    [findbugs] The version of class org.apache.bcel.generic.ObjectType found was not compatible with
    [findbugs] FindBugs.  Please remove any BCEL libraries that may be interfering. This may happen
    [findbugs] if you have an old version of BCEL or a library that includes an old version of BCEL
    [findbugs] in an "endorsed" directory.
    [findbugs] Output saved to C:\\findbugs\\out.html

Why is findbugs not working?

Michael Myers
  • 188,989
  • 46
  • 291
  • 292
user64133
  • 1,149
  • 3
  • 9
  • 10

4 Answers4

2

You've got a conflict with an older version of BCEL that you have to get rid of. It might be in your jre/lib/ext directory (bad idea), or part of the CLASSPATH that you've got for your project, or maybe part of the Ant /lib. In any case, you should find all the BCEL JARs in your CLASSPATH, remove them, and update them with the version that FindBugs requires.

duffymo
  • 305,152
  • 44
  • 369
  • 561
0

Java Version 1.6.0_06 contain old BCEL library.

java version "1.6.0_06" Java(TM) SE Runtime Environment (build 1.6.0_06-b02) Java HotSpot(TM) Client VM (build 10.0-b22, mixed mode)

Once I change to 1.5.0_17 it works fine for me.

lawardy
  • 153
  • 2
  • 3
  • 10
0

I found out that the xalan:xalan:jar:2.6.0 library (which was a transitive dependency of the org.apache.xmlgraphics:batik-bridge:jar:1.7 library in my project) contains the org.apache.bcel.generic.ObjectType class (in a wrong version, perhaps). This class is, perhaps, the one which causes the following error:

[INFO] File Encoding is UTF-8
BCEL class compatability error.
The version of class org.apache.bcel.generic.ObjectType found was not compatible with
FindBugs.  Please remove any BCEL libraries that may be interfering.  This may happen
if you have an old version of BCEL or a library that includes an old version of BCEL
in an "endorsed" directory.
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Java returned: 1
[INFO] ------------------------------------------------------------------------
[INFO] Trace
: Java returned: 1
        at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at groovy.util.AntBuilder.nodeCompleted(AntBuilder.java:199)
        at groovy.util.BuilderSupport.doInvokeMethod(BuilderSupport.java:153)
        at groovy.util.AntBuilder.doInvokeMethod(AntBuilder.java:149)
        at groovy.util.BuilderSupport.invokeMethod(BuilderSupport.java:64)
        at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:784)
        at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:758)
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:170)
        at org.codehaus.mojo.findbugs.FindBugsGui.execute(FindBugsGui.groovy:163)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
        at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)

As the artifact was not needed for compilation (in our case), we just changed its scope to runtime in the Maven pom.xml file and this error disappeared and the mvn clean findbugs:findbugs findbugs:gui works again (at least for me):

  ...
  <dependencies>
    <dependency>
      <groupId>org.apache.xmlgraphics</groupId>
      <artifactId>batik-bridge</artifactId>
      <version>1.7</version>
      <scope>runtime</scope>
    </dependency>
  </dependencies>
  ...

Hope this saves someone's ass...

Jiri Patera
  • 3,140
  • 1
  • 20
  • 14
-1

If findbugs has its own version of BCEL then why do I get this error:

[findbugs] Executing findbugs from ant task
[findbugs] Running FindBugs...
[findbugs] The java class is not found:  org.apache.bcel.classfile.ClassFormatException
[findbugs] Output saved to C:\\findbugs\\out.html

This error occurs if I remove bcel.jar from the findbugs.home directory.

user64133
  • 1,149
  • 3
  • 9
  • 10