Initially raised in https://github.com/spring-projects/spring-boot/issues/38592#issuecomment-1830468522

FileSystems.getFileSystem(URI.create("jar:nested:/Users/rdehuyss/Projects/Personal/jobrunr/examples/example-java-mag/target/example-java-mag-1.0-SNAPSHOT.jar"));

throws the following exception (which I can understand from the docs as it is the new format to retrieve resources):

java.lang.IllegalArgumentException: 'path' must contain '/!'
        at org.springframework.boot.loader.net.protocol.nested.NestedLocation.parse(NestedLocation.java:98)
        at org.springframework.boot.loader.net.protocol.nested.NestedLocation.fromUri(NestedLocation.java:89)
        at org.springframework.boot.loader.nio.file.NestedFileSystemProvider.getPath(NestedFileSystemProvider.java:88)
        at java.base/java.nio.file.Path.of(Path.java:208)
        at java.base/java.nio.file.Paths.get(Paths.java:98)
        at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.uriToPath(ZipFileSystemProvider.java:76)
        at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.newFileSystem(ZipFileSystemProvider.java:98)
        at java.base/java.nio.file.FileSystems.newFileSystem(FileSystems.java:339)
        at java.base/java.nio.file.FileSystems.newFileSystem(FileSystems.java:288)

However,

FileSystems.newFileSystem(URI.create("jar:nested:/Users/rdehuyss/Projects/Personal/jobrunr/examples/example-java-mag/target/example-java-mag-1.0-SNAPSHOT.jar/!BOOT-INF/lib/jobrunr-1.0.0-SNAPSHOT.jar"), Collections.emptyMap());

throws the following exception:

java.util.zip.ZipException: read CEN tables failed
        at jdk.zipfs/jdk.nio.zipfs.ZipFileSystem.initCEN(ZipFileSystem.java:1549)
        at jdk.zipfs/jdk.nio.zipfs.ZipFileSystem.<init>(ZipFileSystem.java:174)
        at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.getZipFileSystem(ZipFileSystemProvider.java:125)
        at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.newFileSystem(ZipFileSystemProvider.java:106)
        at java.base/java.nio.file.FileSystems.newFileSystem(FileSystems.java:339)
        at java.base/java.nio.file.FileSystems.newFileSystem(FileSystems.java:288)

Comment From: philwebb

It looks like ZipFileSystem and NestedFileSystem disagree about the contract of ReadableByteChannel.read.

The nested file system expects that the call can return less bytes than remain in the buffer and the caller will make repeated calls until they're all read. This was because the Javadoc of ReadableByteChannel.read states:

A read operation might not fill the buffer, and in fact it might not read any bytes at all

The ZipFileSystem however has this check if (readFullyAt(cen, 0, cen.length, cenpos) != end.cenlen + ENDHDR). The readFullyAt method does return ch.position(pos).read(bb); which clearly doesn't deal a read that doesn't return everything.