Bug 1080682

Summary: Ant FindBugs task doesn't work due to bad jar manifest file
Product: [Fedora] Fedora Reporter: Matthew Cline <matt>
Component: findbugsAssignee: Richard Fearn <richardfearn>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 20CC: loskutov, richardfearn
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: All   
Whiteboard:
Fixed In Version: findbugs-2.0.3-4.fc20 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-07-05 14:51:50 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Matthew Cline 2014-03-25 23:27:56 UTC
With FindBugs 2.0.3-3, the FindBugs Ant task doesn't work.  Specifically:

1) It first says "java.lang.IllegalArgumentException: Can't find findbugs.jar in /usr/share/findbugs/lib"

2) After making /usr/share/findbugs/lib a symbolic link to /usr/share/java, I get "Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/bcel/classfile/ClassFormatException"

For more details, see this StackOverflow question:  http://stackoverflow.com/questions/21795698/findbugs-cant-locate-org-apache-bcel-classfile-classformatexception

I then filed a bug report with the FindBugs folks: https://sourceforge.net/p/findbugs/bugs/1255/

They told me that the problem is that the manifest file for the findbugs.jar file is wrong, and it should look like this: http://code.google.com/p/findbugs/source/browse/findbugs/etc/MANIFEST-findbugs.MF

Might be related to bug 575632

Comment 1 Andrey Loskutov 2014-03-27 19:05:17 UTC
Not sure where to find the right code for this bug. 
According to the http://pkgs.fedoraproject.org/cgit/findbugs.git/log/?h=f20
fedora 20 must have the *right* manifest including libraries: http://pkgs.fedoraproject.org/cgit/findbugs.git/commit/?h=f20&id=8449f7ae72e7d5e24fb26a8d494197153fac2fa8

Comment 2 Richard Fearn 2014-04-11 07:04:21 UTC
I'll be able to look into this after 2014-04-16.

Comment 3 Richard Fearn 2014-04-19 14:57:08 UTC
(In reply to Matthew Cline from comment #0)

> They told me that the problem is that the manifest file for the findbugs.jar
> file is wrong, and it should look like this:
> http://code.google.com/p/findbugs/source/browse/findbugs/etc/MANIFEST-
> findbugs.MF

(In reply to Andrey Loskutov from comment #1)

> Not sure where to find the right code for this bug. 
> According to the http://pkgs.fedoraproject.org/cgit/findbugs.git/log/?h=f20
> fedora 20 must have the *right* manifest including libraries:
> http://pkgs.fedoraproject.org/cgit/findbugs.git/commit/
> ?h=f20&id=8449f7ae72e7d5e24fb26a8d494197153fac2fa8

Fedora packaging guidelines (https://fedoraproject.org/wiki/Packaging:Java) don't allow manifest files within JAR files to have Class-Path entries, so this gets removed (http://pkgs.fedoraproject.org/cgit/findbugs.git/tree/findbugs-fedora.patch#n1) from the manifest file that goes into findbugs.jar.

Instead the findbugs launcher script is modified (http://pkgs.fedoraproject.org/cgit/findbugs.git/tree/findbugs-fedora.patch#n63) to use the build-classpath command to build up the correct classpath for FindBugs.

In FindBugs 2.0.3, the Ant build script doesn't include *any* manifest into findbugs-ant.jar (or ant-findbugs.jar, as it's called on Fedora). This is still the case for FindBugs master: http://code.google.com/p/findbugs/source/browse/findbugs/build.xml#343

I'll take a look at why the Ant task doesn't work...

Comment 4 Richard Fearn 2014-04-19 18:29:07 UTC
(In reply to Richard Fearn from comment #3)
> I'll take a look at why the Ant task doesn't work...

/etc/ant.d/findbugs lists the Java libraries that are required for FindBugs to work. /usr/bin/ant does include these libraries on the classpath when running Ant:

$ ant --execdebug
exec "/usr/bin/java" -classpath "[...]:/usr/share/java/findbugs.jar:/usr/share/java/ant/ant-findbugs.jar:/usr/share/java/apache-commons-lang.jar:/usr/share/java/dom4j.jar:/usr/share/java/findbugs-bcel.jar:/usr/share/java/jaxen.jar:/usr/share/java/jcip-annotations.jar:/usr/share/java/jFormatString.jar:/usr/share/java/jsr-305.jar:/usr/share/java/junit.jar:/usr/share/java/objectweb-asm/asm.jar:/usr/share/java/objectweb-asm/asm-commons.jar:/usr/share/java/objectweb-asm/asm-tree.jar:[...]" -Dant.home="/usr/share/ant" -Dant.library.dir="/usr/share/ant/lib" org.apache.tools.ant.launch.Launcher -cp ""

However the Ant task itself forks a new Java VM to run FindBugs.

The Ant task requires either the 'home' or 'classpath' attribute to be specified. If 'home' is specified, the task puts <home>/lib/findbugs.jar on the classpath. If 'classpath' is specified, that classpath is used as-is.

I guess most people do <findbugs home='...'> so that findbugs.jar goes onto the classpath, and since findbugs.jar usually contains a manifest with a Class-Path entry, all the dependencies can be found.

That doesn't work on Fedora, since the Class-Path entry is not included in findbugs.jar.

As a workaround it's possible to do this:

<findbugs classpath="/usr/share/java/findbugs.jar:/usr/share/java/ant/ant-findbugs.jar:/usr/share/java/apache-commons-lang.jar:/usr/share/java/dom4j.jar:/usr/share/java/findbugs-bcel.jar:/usr/share/java/jaxen.jar:/usr/share/java/jcip-annotations.jar:/usr/share/java/jFormatString.jar:/usr/share/java/jsr-305.jar:/usr/share/java/junit.jar:/usr/share/java/objectweb-asm/asm.jar:/usr/share/java/objectweb-asm/asm-commons.jar:/usr/share/java/objectweb-asm/asm-tree.jar">

where that classpath is the output from:

$ build-classpath `cat /etc/ant.d/findbugs`

Comment 5 Richard Fearn 2014-06-22 17:33:10 UTC
This should be fixed in 2.0.3-8 for rawhide now:

http://koji.fedoraproject.org/koji/buildinfo?buildID=539462

Fedora 20 update to follow...

Comment 6 Fedora Update System 2014-06-22 18:11:51 UTC
findbugs-2.0.3-4.fc20 has been submitted as an update for Fedora 20.
https://admin.fedoraproject.org/updates/findbugs-2.0.3-4.fc20

Comment 7 Fedora Update System 2014-06-24 01:59:08 UTC
Package findbugs-2.0.3-4.fc20:
* should fix your issue,
* was pushed to the Fedora 20 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing findbugs-2.0.3-4.fc20'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2014-7670/findbugs-2.0.3-4.fc20
then log in and leave karma (feedback).

Comment 8 Fedora Update System 2014-07-05 14:51:50 UTC
findbugs-2.0.3-4.fc20 has been pushed to the Fedora 20 stable repository.  If problems still persist, please make note of it in this bug report.