buck icon indicating copy to clipboard operation
buck copied to clipboard

prebuilt_jar fails when the jar has duplicate entries in it.

Open rbraunstein opened this issue 12 years ago • 10 comments

BUILD FAILED: //third-party/jmdns-3.4.0-jenkins-3-jar:jmdns-3.4.0-jenkins-3-jar failed on step get_class_names Optional.of(third-party/jmdns-3.4.0-jenkins-3-jar/jmdns-3.4.0-jenkins-3.jar) > buck-out/gen/third-party/jmdns-3.4.0-jenkins-3-jar/jmdns-3.4.0-jenkins-3-jar.classes.txt with an exception: Multiple entries with same key: com/strangeberry/jmdns/tools/Browser=903578aa54046efcab5fde9f4b5f229155897dac and com/strangeberry/jmdns/tools/Browser=903578aa54046efcab5fde9f4b5f229155897dac

In this jar, some classes are duplicated: http://maven.jenkins-ci.org/content/repositories/releases/org/jenkins-ci/jmdns/3.4.0-jenkins-3/

% jar -tvf ~/Downloads/jmdns-3.4.0-jenkins-3.jar | grep Browser 709 Tue Aug 09 13:24:14 PDT 2011 com/strangeberry/jmdns/tools/Browser$1.class 713 Tue Aug 09 13:24:14 PDT 2011 com/strangeberry/jmdns/tools/Browser$2.class 711 Tue Aug 09 13:24:14 PDT 2011 com/strangeberry/jmdns/tools/Browser$3.class 950 Tue Aug 09 13:24:14 PDT 2011 com/strangeberry/jmdns/tools/Browser$ServiceTableModel.class 6297 Tue Aug 09 13:24:14 PDT 2011 com/strangeberry/jmdns/tools/Browser.class 709 Tue Aug 09 13:24:14 PDT 2011 com/strangeberry/jmdns/tools/Browser$1.class 713 Tue Aug 09 13:24:14 PDT 2011 com/strangeberry/jmdns/tools/Browser$2.class 711 Tue Aug 09 13:24:14 PDT 2011 com/strangeberry/jmdns/tools/Browser$3.class 950 Tue Aug 09 13:24:14 PDT 2011 com/strangeberry/jmdns/tools/Browser$ServiceTableModel.class 6297 Tue Aug 09 13:24:14 PDT 2011 com/strangeberry/jmdns/tools/Browser.class

rbraunstein avatar Jan 22 '14 00:01 rbraunstein

At Facebook, we dealt with this by just fixing our third-party jars. I would suggest reporting this upstream, since there isn't a clear, safe way for Buck to deal with this.

dreiss avatar Jan 22 '14 01:01 dreiss

Yeah, I tend to think of this as being similar to a corrupted JAR in the sense that it's something that buck can't and shouldn't know how to handle (e.g. which of the class files should we drop?). What about using a genrule to run "zip -d ..." to remove the offending entries and then have the output plug into the prebuilt_jar rule? Would something like this work for you?

andrewjcg avatar Jun 10 '14 01:06 andrewjcg

In the case I was looking at, the two entries were exactly the same.

On Mon, Jun 9, 2014 at 6:00 PM, andrewjcg [email protected] wrote:

Yeah, I tend to think of this as being similar to a corrupted JAR in the sense that it's something that buck can't and shouldn't know how to handle (e.g. which of the class files should we drop?). What about using a genrule to run "zip -d ..." to remove the offending entries and then have the output plug into the prebuilt_jar rule? Would something like this work for you?

— Reply to this email directly or view it on GitHub https://github.com/facebook/buck/issues/84#issuecomment-45563017.

rbraunstein avatar Jun 10 '14 02:06 rbraunstein

If you give Buck a prebuilt jar that is broken, bad things will happen. @dreiss and @andrewjcg are right; the right way to fix this is to correct the jar.

sdwilsh avatar Dec 30 '14 23:12 sdwilsh

@sdwilsh I'd like to request that this issue be re-opened (and re-visited). In our case, we do not check-in jars but instead resolve them from maven. One of our dependencies, org.apache.xmlbeans:xmlbeans:2.6.0, is built with duplicate class entries.

As expected, the result is:

BUILD FAILED: //ThirdParty:xmlbeans failed on step get_class_names with an exception:
Multiple entries with same key:
  org/apache/xmlbeans/xml/stream/Location=b010d46296931435514ab3d6237b17e03df64e5b
  org/apache/xmlbeans/xml/stream/Location=b010d46296931435514ab3d6237b17e03df64e5b

However, as in the case for @rbraunstein, the duplicate classes are identical, yielding the same hash. As the zlib specification allows duplicate entries, it seems the correct handling would be to simply ignore one of the classes, provided that the hashes match.

Of course, if the classes are truly different an error is warranted.

Given that xmlbeans hasn't updated since 2013 it seems unlikely that an upstream fix will be available in a timely fashion (though we will certainly open an issue there). At that same time, we are loath to alter our build process to accommodate a single jar issue. Again, it seems like buck can both easily and safely resolve the issue by simply ignoring classes with identical keys and identical hashes.

ADDENDUM: The recommendation of altering the jar breaks the auditing and security guarantees provided by the SHA1 lineage as published by the originator.

brettwooldridge avatar Oct 24 '16 08:10 brettwooldridge

I haven't actively worked on the Buck project in over nine months, so I'm going to cc @Coneko who is my best guess for someone who might be able to respond to you, @brettwooldridge.

sdwilsh avatar Oct 24 '16 16:10 sdwilsh

I'll cc @shs96c and @ryandm since I have no idea about maven.

Coneko avatar Oct 24 '16 23:10 Coneko

Thanks guys. In the meantime I'm cooking up a pull request for review, looks like a one or two line change.

brettwooldridge avatar Oct 24 '16 23:10 brettwooldridge

This issue isn't precisely maven related, but agreed on @brettwooldridge's assessment of dissatisfaction with workarounds (which I've also seen in practice) and that allowing identical duplicates is practical here. A pull request would be awesome.

ryandm avatar Oct 25 '16 00:10 ryandm

@ryandm Not that it matters so much, but the code in the pull request throws a nearly identical exception to the one previously being throw by guava.

brettwooldridge avatar Oct 26 '16 12:10 brettwooldridge