Starting with Spring Boot 1.5.14.RELEASE, we get an exception when building with maven (mvn clean install) at goal repackage. This only happens when there is a resource file with nothing but two empty lines on the classpath.
Please see attached project invalidentrysize.zip for reproducing the exception.
Also added a sample-project under spring-boot-issues via pull request (https://github.com/spring-projects/spring-boot-issues/pull/78). I'm not sure if the sample from the pull request will work, because our enterprise GitHub shows "2 lines (0 sloc) 1 Byte" and GitHub.com shows "2 lines (0 sloc) 2 Bytes" for that special file.
Stacktrace:
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.14.RELEASE:repackage (default) on project invalid-entry-size: invalid entry size (expected 2 but got 1 bytes) -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.14.RELEASE:repackage (default) on project invalid-entry-size: invalid entry size (expected 2 but got 1 bytes)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
Caused by: org.apache.maven.plugin.MojoExecutionException: invalid entry size (expected 2 but got 1 bytes)
at org.springframework.boot.maven.RepackageMojo.repackage(RepackageMojo.java:220)
at org.springframework.boot.maven.RepackageMojo.execute(RepackageMojo.java:204)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
... 21 more
Caused by: java.util.zip.ZipException: invalid entry size (expected 2 but got 1 bytes)
at java.util.zip.ZipOutputStream.closeEntry(ZipOutputStream.java:262)
at org.springframework.boot.loader.tools.JarWriter.writeEntry(JarWriter.java:268)
at org.springframework.boot.loader.tools.JarWriter.writeEntries(JarWriter.java:146)
at org.springframework.boot.loader.tools.Repackager.repackage(Repackager.java:281)
at org.springframework.boot.loader.tools.Repackager.repackage(Repackager.java:262)
at org.springframework.boot.loader.tools.Repackager.repackage(Repackager.java:194)
at org.springframework.boot.maven.RepackageMojo.repackage(RepackageMojo.java:217)
... 24 more
Thanks. https://github.com/spring-projects/spring-boot/pull/13480 is intended to fix this but, now that I know a file with two blanks lines is required to trigger the problem, adding a test to #13480 reveals that the proposed fix is insufficient. This test fails both with and without the proposed fix:
@Test
public void fileWithTwoBlankLinks() throws Exception {
this.testJarFile.addClass("a/b/C.class", ClassWithMainMethod.class);
File createTempFile = File.createTempFile("empty", ".txt");
Files.write(createTempFile.toPath(), Arrays.asList("", ""));
this.testJarFile.addFile("empty.txt", createTempFile);
File file = this.testJarFile.getFile();
Repackager repackager = new Repackager(file);
repackager.repackage(NO_LIBRARIES);
}
I'm going to close the PR in favour of this issue.
Hi,
Has this been fixed in 1.5.x release yet?
Yes, but it hasn't been released yet, you are welcome to try snapshots.
@spencergibb
Thank you for the timely reply and confirmation!
Is there any workaround for this ?
You could try a snapshot or avoid repackaging files that are <=4 bytes in length.
How can we avoid them?
Only you can answer that as you know what files you have and what purpose they serve.
Not fixed yet, I felt into the trap yesterday :)
@angelosphere This should be fixed in 1.5.15 in later. If you are using such a version and the problem is occurring, please open a new issue with a minimal sample that reproduces the problem and we will take a look.
Funny, by accident I used exact the version mentioned in this topic, I switched to 2.2.0.M3, all is fine.
Most helpful comment
Thanks. https://github.com/spring-projects/spring-boot/pull/13480 is intended to fix this but, now that I know a file with two blanks lines is required to trigger the problem, adding a test to #13480 reveals that the proposed fix is insufficient. This test fails both with and without the proposed fix:
I'm going to close the PR in favour of this issue.