gradlex-org/extra-java-module-info

ZipException: invalid entry compressed size error with Java < 16

Closed this issue · 2 comments

The plugin seems to be reusing JarEntry entries when adding the automatic module name in ExtraModuleInfoTransform, and with Java versions prior to 16 this may lead to errors like the following:

Caused by: java.lang.RuntimeException: java.util.zip.ZipException: invalid entry compressed size (expected 1665 but got 1680 bytes)
        at de.jjohannes.gradle.javamodules.ExtraModuleInfoTransform.addAutomaticModuleName(ExtraModuleInfoTransform.java:137)
        at de.jjohannes.gradle.javamodules.ExtraModuleInfoTransform.transform(ExtraModuleInfoTransform.java:64)
        at org.gradle.api.internal.artifacts.transform.DefaultTransformer.transform(DefaultTransformer.java:264)
        at org.gradle.api.internal.artifacts.transform.DefaultTransformerInvocationFactory$AbstractTransformerExecution$1.call(DefaultTransformerInvocationFactory.java:296)
        at org.gradle.api.internal.artifacts.transform.DefaultTransformerInvocationFactory$AbstractTransformerExecution$1.call(DefaultTransformerInvocationFactory.java:291)

The above exception trace was triggered by the org.w3c.css:sac:1.3 artifact with extra-java-module-info version 0.10:

extraJavaModuleInfo {
    automaticModule('sac-1.3.jar', 'sac')
}

Issue context

From the JDK bug 8253952:

The correct way of copying all entries from one zip file into another requires the creation of a new ZipEntry or at least resetting of the compressed size field. E.g.:

 while((entry = zis.getNextEntry()) != null) {
     ZipEntry newEntry = new ZipEntry(entry.getName());
     zos.putNextEntry(newEntry);
     zis.transferTo(zos);
 }

or:

 while((entry = zis.getNextEntry()) != null) {
     entry.setCompressedSize(-1);
     zos.putNextEntry(entry);
     zis.transferTo(zos);
 }

That JDK issue is very detailed and almost says it all, but there is also a blog post that covers the topic: How to programmatically copy jar files.

How to reproduce

To reproduce the error, clone the CSS4J repository and build the 1-stable branch with Java 11:

git clone https://github.com/css4j/css4j.git
cd css4j
git checkout 1-stable
export JAVA_HOME="C:\\Program Files\\Eclipse Adoptium\\jdk-11.0.14.9-hotspot\\" # or your path to Java 11
./gradlew build

Thanks for reporting this @carlosame and that you @iherasymenko so quickly.

I will do a new release with the fix soon.

Fix is in 0.11