Under Spring Boot 3.2.x I get a java.lang.NegativeArraySizeException exception from org.springframework.boot.loader.zip.ZipContent$Loader when running:
java -Djarmode=layertools -jar target/*.jar extract --destination target/extracted
if the project has snowflake-jdbc 3.14.x as a dependency.
If I use Spring Boot 3.1.x it works without problem.
If I downgrade snowflake-jdbc to version 3.13.x it also works on Spring Boot 3.2.x without problem.
I checked both with Java 21 and Java 17 with same results.
In https://github.com/rubensa/layertools you can find a sample repo showing the problem (based in VSCode with Dev Containers -you need to switch to Language Support for Java(TM) by Red Hat pre-release extension version as Java 21 is not yet officially supported-).
If you run build.sh in main branch (Java 21, Spring Boot 3.2.0 and snowflake-jdbc 3.14.3) you get:
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< org.eu.rubensa:layertools >----------------------
[INFO] Building layertools 0.0.1-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- clean:3.3.2:clean (default-clean) @ layertools ---
[INFO] Deleting /workspaces/layertools/target
[INFO]
[INFO] --- resources:3.3.1:resources (default-resources) @ layertools ---
[INFO] Copying 1 resource from src/main/resources to target/classes
[INFO] Copying 0 resource from src/main/resources to target/classes
[INFO]
[INFO] --- compiler:3.11.0:compile (default-compile) @ layertools ---
[INFO] Changes detected - recompiling the module! :source
[INFO] Compiling 1 source file with javac [debug release 21] to target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.166 s
[INFO] Finished at: 2023-11-27T17:17:09Z
[INFO] ------------------------------------------------------------------------
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< org.eu.rubensa:layertools >----------------------
[INFO] Building layertools 0.0.1-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- resources:3.3.1:resources (default-resources) @ layertools ---
[INFO] Copying 1 resource from src/main/resources to target/classes
[INFO] Copying 0 resource from src/main/resources to target/classes
[INFO]
[INFO] --- compiler:3.11.0:compile (default-compile) @ layertools ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- resources:3.3.1:testResources (default-testResources) @ layertools ---
[INFO] skip non existing resourceDirectory /workspaces/layertools/src/test/resources
[INFO]
[INFO] --- compiler:3.11.0:testCompile (default-testCompile) @ layertools ---
[INFO] Changes detected - recompiling the module! :source
[INFO] Compiling 1 source file with javac [debug release 21] to target/test-classes
[INFO]
[INFO] --- surefire:3.1.2:test (default-test) @ layertools ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running org.eu.rubensa.layertools.LayertoolsApplicationTests
17:17:11.755 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils -- Could not detect default configuration classes for test class [org.eu.rubensa.layertools.LayertoolsApplicationTests]: LayertoolsApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
17:17:11.810 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper -- Found @SpringBootConfiguration org.eu.rubensa.layertools.LayertoolsApplication for test class org.eu.rubensa.layertools.LayertoolsApplicationTests
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.2.0)
2023-11-27T17:17:12.017Z INFO 3061 --- [ main] o.e.r.l.LayertoolsApplicationTests : Starting LayertoolsApplicationTests using Java 21.0.1 with PID 3061 (started by user in /workspaces/layertools)
2023-11-27T17:17:12.018Z INFO 3061 --- [ main] o.e.r.l.LayertoolsApplicationTests : No active profile set, falling back to 1 default profile: "default"
2023-11-27T17:17:12.564Z INFO 3061 --- [ main] o.e.r.l.LayertoolsApplicationTests : Started LayertoolsApplicationTests in 0.695 seconds (process running for 1.249)
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
WARNING: A Java agent has been loaded dynamically (/home/user/.m2/repository/net/bytebuddy/byte-buddy-agent/1.14.10/byte-buddy-agent-1.14.10.jar)
WARNING: If a serviceability tool is in use, please run with -XX:+EnableDynamicAgentLoading to hide this warning
WARNING: If a serviceability tool is not in use, please run with -Djdk.instrument.traceUsage for more information
WARNING: Dynamic loading of agents will be disallowed by default in a future release
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.468 s -- in org.eu.rubensa.layertools.LayertoolsApplicationTests
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- jar:3.3.0:jar (default-jar) @ layertools ---
[INFO] Building jar: /workspaces/layertools/target/layertools-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot:3.2.0:repackage (repackage) @ layertools ---
[INFO] Replacing main artifact /workspaces/layertools/target/layertools-0.0.1-SNAPSHOT.jar with repackaged archive, adding nested dependencies in BOOT-INF/.
[INFO] The original artifact has been renamed to /workspaces/layertools/target/layertools-0.0.1-SNAPSHOT.jar.original
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.782 s
[INFO] Finished at: 2023-11-27T17:17:13Z
[INFO] ------------------------------------------------------------------------
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:118)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:91)
at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:53)
at org.springframework.boot.loader.launch.JarLauncher.main(JarLauncher.java:58)
Caused by: java.lang.NegativeArraySizeException: -31658
at org.springframework.boot.loader.zip.ZipContent$Loader.<init>(ZipContent.java:435)
at org.springframework.boot.loader.zip.ZipContent$Loader.loadContent(ZipContent.java:565)
at org.springframework.boot.loader.zip.ZipContent$Loader.openAndLoad(ZipContent.java:543)
at org.springframework.boot.loader.zip.ZipContent$Loader.loadNestedZip(ZipContent.java:537)
at org.springframework.boot.loader.zip.ZipContent$Loader.load(ZipContent.java:522)
at org.springframework.boot.loader.zip.ZipContent.open(ZipContent.java:372)
at org.springframework.boot.loader.zip.ZipContent.open(ZipContent.java:361)
at org.springframework.boot.loader.jar.NestedJarFileResources.<init>(NestedJarFileResources.java:57)
at org.springframework.boot.loader.jar.NestedJarFile.<init>(NestedJarFile.java:141)
at org.springframework.boot.loader.jar.NestedJarFile.<init>(NestedJarFile.java:120)
at org.springframework.boot.loader.net.protocol.jar.UrlNestedJarFile.<init>(UrlNestedJarFile.java:42)
at org.springframework.boot.loader.net.protocol.jar.UrlJarFileFactory.createJarFileForNested(UrlJarFileFactory.java:86)
at org.springframework.boot.loader.net.protocol.jar.UrlJarFileFactory.createJarFile(UrlJarFileFactory.java:55)
at org.springframework.boot.loader.net.protocol.jar.UrlJarFiles.getOrCreate(UrlJarFiles.java:72)
at org.springframework.boot.loader.net.protocol.jar.JarUrlConnection.connect(JarUrlConnection.java:289)
at org.springframework.boot.loader.net.protocol.jar.JarUrlConnection.getJarFile(JarUrlConnection.java:99)
at org.springframework.boot.loader.net.protocol.jar.JarUrlClassLoader.getJarFile(JarUrlClassLoader.java:185)
at org.springframework.boot.loader.net.protocol.jar.JarUrlClassLoader.definePackage(JarUrlClassLoader.java:143)
at org.springframework.boot.loader.net.protocol.jar.JarUrlClassLoader.definePackageIfNecessary(JarUrlClassLoader.java:126)
at org.springframework.boot.loader.net.protocol.jar.JarUrlClassLoader.loadClass(JarUrlClassLoader.java:99)
at org.springframework.boot.loader.launch.LaunchedClassLoader.loadClass(LaunchedClassLoader.java:91)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
at org.springframework.boot.loader.launch.JarModeRunner.main(JarModeRunner.java:40)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
... 4 more
If you run build.sh in java-21-spring-boot-3.2.x-snowflake-jdbc-3.13.x branch (Java 21, Spring Boot 3.2.0 and snowflake-jdbc 3.13.33) you get:
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< org.eu.rubensa:layertools >----------------------
[INFO] Building layertools 0.0.1-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- clean:3.3.2:clean (default-clean) @ layertools ---
[INFO] Deleting /workspaces/layertools/target
[INFO]
[INFO] --- resources:3.3.1:resources (default-resources) @ layertools ---
[INFO] Copying 1 resource from src/main/resources to target/classes
[INFO] Copying 0 resource from src/main/resources to target/classes
[INFO]
[INFO] --- compiler:3.11.0:compile (default-compile) @ layertools ---
[INFO] Changes detected - recompiling the module! :source
[INFO] Compiling 1 source file with javac [debug release 21] to target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.264 s
[INFO] Finished at: 2023-11-27T17:17:54Z
[INFO] ------------------------------------------------------------------------
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< org.eu.rubensa:layertools >----------------------
[INFO] Building layertools 0.0.1-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- resources:3.3.1:resources (default-resources) @ layertools ---
[INFO] Copying 1 resource from src/main/resources to target/classes
[INFO] Copying 0 resource from src/main/resources to target/classes
[INFO]
[INFO] --- compiler:3.11.0:compile (default-compile) @ layertools ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- resources:3.3.1:testResources (default-testResources) @ layertools ---
[INFO] skip non existing resourceDirectory /workspaces/layertools/src/test/resources
[INFO]
[INFO] --- compiler:3.11.0:testCompile (default-testCompile) @ layertools ---
[INFO] Changes detected - recompiling the module! :source
[INFO] Compiling 1 source file with javac [debug release 21] to target/test-classes
[INFO]
[INFO] --- surefire:3.1.2:test (default-test) @ layertools ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running org.eu.rubensa.layertools.LayertoolsApplicationTests
17:17:57.337 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils -- Could not detect default configuration classes for test class [org.eu.rubensa.layertools.LayertoolsApplicationTests]: LayertoolsApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
17:17:57.398 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper -- Found @SpringBootConfiguration org.eu.rubensa.layertools.LayertoolsApplication for test class org.eu.rubensa.layertools.LayertoolsApplicationTests
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.2.0)
2023-11-27T17:17:57.593Z INFO 3634 --- [ main] o.e.r.l.LayertoolsApplicationTests : Starting LayertoolsApplicationTests using Java 21.0.1 with PID 3634 (started by user in /workspaces/layertools)
2023-11-27T17:17:57.594Z INFO 3634 --- [ main] o.e.r.l.LayertoolsApplicationTests : No active profile set, falling back to 1 default profile: "default"
2023-11-27T17:17:58.173Z INFO 3634 --- [ main] o.e.r.l.LayertoolsApplicationTests : Started LayertoolsApplicationTests in 0.708 seconds (process running for 1.274)
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
WARNING: A Java agent has been loaded dynamically (/home/user/.m2/repository/net/bytebuddy/byte-buddy-agent/1.14.10/byte-buddy-agent-1.14.10.jar)
WARNING: If a serviceability tool is in use, please run with -XX:+EnableDynamicAgentLoading to hide this warning
WARNING: If a serviceability tool is not in use, please run with -Djdk.instrument.traceUsage for more information
WARNING: Dynamic loading of agents will be disallowed by default in a future release
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.453 s -- in org.eu.rubensa.layertools.LayertoolsApplicationTests
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- jar:3.3.0:jar (default-jar) @ layertools ---
[INFO] Building jar: /workspaces/layertools/target/layertools-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot:3.2.0:repackage (repackage) @ layertools ---
[INFO] Replacing main artifact /workspaces/layertools/target/layertools-0.0.1-SNAPSHOT.jar with repackaged archive, adding nested dependencies in BOOT-INF/.
[INFO] The original artifact has been renamed to /workspaces/layertools/target/layertools-0.0.1-SNAPSHOT.jar.original
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.641 s
[INFO] Finished at: 2023-11-27T17:17:59Z
[INFO] ------------------------------------------------------------------------
If you run build.sh in java-21-spring-boot-3.1.x-snowflake-3.14.x branch (Java 21, Spring Boot 3.1.5 and snowflake-jdbc 3.14.x) you get:
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< org.eu.rubensa:layertools >----------------------
[INFO] Building layertools 0.0.1-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- clean:3.2.0:clean (default-clean) @ layertools ---
[INFO] Deleting /workspaces/layertools/target
[INFO]
[INFO] --- resources:3.3.1:resources (default-resources) @ layertools ---
[INFO] Copying 1 resource from src/main/resources to target/classes
[INFO] Copying 0 resource from src/main/resources to target/classes
[INFO]
[INFO] --- compiler:3.11.0:compile (default-compile) @ layertools ---
[INFO] Changes detected - recompiling the module! :source
[INFO] Compiling 1 source file with javac [debug release 21] to target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.368 s
[INFO] Finished at: 2023-11-27T17:18:54Z
[INFO] ------------------------------------------------------------------------
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< org.eu.rubensa:layertools >----------------------
[INFO] Building layertools 0.0.1-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- resources:3.3.1:resources (default-resources) @ layertools ---
[INFO] Copying 1 resource from src/main/resources to target/classes
[INFO] Copying 0 resource from src/main/resources to target/classes
[INFO]
[INFO] --- compiler:3.11.0:compile (default-compile) @ layertools ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- resources:3.3.1:testResources (default-testResources) @ layertools ---
[INFO] skip non existing resourceDirectory /workspaces/layertools/src/test/resources
[INFO]
[INFO] --- compiler:3.11.0:testCompile (default-testCompile) @ layertools ---
[INFO] Changes detected - recompiling the module! :source
[INFO] Compiling 1 source file with javac [debug release 21] to target/test-classes
[INFO]
[INFO] --- surefire:3.0.0:test (default-test) @ layertools ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running org.eu.rubensa.layertools.LayertoolsApplicationTests
17:18:57.857 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils -- Could not detect default configuration classes for test class [org.eu.rubensa.layertools.LayertoolsApplicationTests]: LayertoolsApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
17:18:57.926 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper -- Found @SpringBootConfiguration org.eu.rubensa.layertools.LayertoolsApplication for test class org.eu.rubensa.layertools.LayertoolsApplicationTests
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.1.5)
2023-11-27T17:18:58.241Z INFO 4612 --- [ main] o.e.r.l.LayertoolsApplicationTests : Starting LayertoolsApplicationTests using Java 21.0.1 with PID 4612 (started by user in /workspaces/layertools)
2023-11-27T17:18:58.243Z INFO 4612 --- [ main] o.e.r.l.LayertoolsApplicationTests : No active profile set, falling back to 1 default profile: "default"
2023-11-27T17:18:59.031Z INFO 4612 --- [ main] o.e.r.l.LayertoolsApplicationTests : Started LayertoolsApplicationTests in 1.014 seconds (process running for 1.727)
WARNING: A Java agent has been loaded dynamically (/home/user/.m2/repository/net/bytebuddy/byte-buddy-agent/1.14.9/byte-buddy-agent-1.14.9.jar)
WARNING: If a serviceability tool is in use, please run with -XX:+EnableDynamicAgentLoading to hide this warning
WARNING: If a serviceability tool is not in use, please run with -Djdk.instrument.traceUsage for more information
WARNING: Dynamic loading of agents will be disallowed by default in a future release
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.955 s - in org.eu.rubensa.layertools.LayertoolsApplicationTests
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- jar:3.3.0:jar (default-jar) @ layertools ---
[INFO] Building jar: /workspaces/layertools/target/layertools-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot:3.1.5:repackage (repackage) @ layertools ---
[INFO] Replacing main artifact /workspaces/layertools/target/layertools-0.0.1-SNAPSHOT.jar with repackaged archive, adding nested dependencies in BOOT-INF/.
[INFO] The original artifact has been renamed to /workspaces/layertools/target/layertools-0.0.1-SNAPSHOT.jar.original
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.992 s
[INFO] Finished at: 2023-11-27T17:19:00Z
[INFO] ------------------------------------------------------------------------
You can run the same using Java 17 from java-17-xxx branches with same results.
Comment From: philwebb
Thanks very much for the sample @rubensa. This was caused by a missing short -> unsigned int conversion.
Comment From: davidfritch
I just wanted to second that I saw this same error running spring-boot 3.2.0 as a .war. When I ran it using the 3.2.1-SNAPSHOT it was not happening anymore.