Invoke MR-JAR file verifier on command line without actually packaging

Uwe Schindler uschindler at apache.org
Wed Sep 27 10:31:42 UTC 2017


Hi,

I am building a multi-release JAR file using Apache Ant (for Lucene, see https://issues.apache.org/jira/browse/LUCENE-7966).

As build tools like Ant/Gradle/Maven are packaging JAR files on their own, not using the official JAR tool, I wanted to do a quick check if the resulting JAR file is valid. https://bugs.openjdk.java.net/browse/JDK-8158295 added some checks to compare method signatures and class file between the base and the META-INF/versions occurrences.

Is there a way to invoke those checks on an already packaged JAR file?

Uwe

P.S.: Just a bit of background for those who are interested! This is a totally new way to create a MR JAR by just pacthing the already compiled class files before packaging as JAR file. The use case here is:
- We want to use java.util.Arrays / java.util.Objects static methods throughout Lucene, especially to improve bounds checks by having Java 9 use the intrinsics when accessing arrays/ByteBuffers. We have already seen a huge speed improvement for our implementation of the LZ4 compression!
- We need to be compatible with Java 8, but improve Java 9.
- So we compile all our Lucene classes against a "custom" variant of the interesting methods, located in a fallback classes we have implemented in our own org.apache.lucene.future.FutureArrays/FutureObjects.
- We do not want to duplicate our code by creating clonesof all .java files that use these methods and we still want to still compile against Java 8 - as this is the release JDK version! We want it automatic!

So our trick is new and also way cool: During packaging the JAR file we patch all class files using ASM's ClassRemapper and replace the Type org.apache.lucene.future.FutureArrays by java.util.Arrays, only for those that actually contain a reference to our own replacement methods. This is a 74-liner in Groovy! After patching we also place the patched files in the MR part of JAR file.

Patch can be seen here:
https://github.com/apache/lucene-solr/compare/master...uschindler:jira/LUCENE-7966-v2

Especially this is how we patch our class files, way cool:
https://github.com/uschindler/lucene-solr/blob/d67eb6274d4c0b8315848db3f09809fbc0797f6e/lucene/core/src/tools/groovy/patch-mrjar-classes.groovy

-----
Uwe Schindler
uschindler at apache.org 
ASF Member, Apache Lucene PMC / Committer
Bremen, Germany
http://lucene.apache.org/




More information about the core-libs-dev mailing list