Repository navigation
Closed
Description
We have classpath scanner which reads all jars. It stumbles on nested jars packed by spring-boot.
AbstractDataLoader.ScanJarFileTask opens them with Files.newInputStream(), which ends up on NestedByteChannel.
E 260827 112253.294 [ForkJoinPool.commonPool-worker-13] AssignableClassesLoader - Error scan jar file: /opt/xt/gateway/lib/gateway.jar/!BOOT-INF/lib/metrics-515.jar
java.io.EOFException: Unexpected end of ZLIB input stream
at java.base/java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:266)
at java.base/java.util.zip.InflaterInputStream.read(InflaterInputStream.java:175)
at java.base/java.util.zip.ZipInputStream.read(ZipInputStream.java:412)
at java.base/java.util.zip.ZipInputStream.closeEntry(ZipInputStream.java:171)
at java.base/java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:149)
at com.loaders.AbstractDataLoader$ScanJarFileTask.compute(AbstractDataLoader.java:257)
int total = 0;
while (dst.remaining() > 0) {
int count = resources.getData().read(dst, position);
if (count <= 0)
return (total != 0) ? 0 : count; // <- should return total
total += count; position += count;
}
return total;
What scanner does:
Gathers jars and directories:
private static Set<URL> getResources(@Nonnull ClassLoader classLoader, @Nonnull String path) throws IOException {
Enumeration<URL> resources = classLoader.getResources(path);
Set<URL> result = new LinkedHashSet<>();
while (resources.hasMoreElements()) {
result.add(resources.nextElement());
}
return result;
}
Filters jar files:
@Nonnull
private static URI extractJarPath(@Nonnull URL jarResource) {
// example input: 'jar:file:/opt/xt/api-209.jar!/com/api/descriptors'
String fileResource = jarResource.getFile();
// fileResource: 'file:/opt/api-209.jar!/com/api/descriptors'
int jarIndex = fileResource.lastIndexOf(".jar!");
if (jarIndex == -1) {
throw new IllegalArgumentException("Unexpected jar resource URL with '.jar!' in it: " + jarResource);
}
String fileOnlyUri = fileResource.substring(0, jarIndex + 4);
int mainJarIndex = fileResource.indexOf(".jar!");
// uber-jar spring-boot
if (mainJarIndex != jarIndex) {
return URI.create("jar:" + fileOnlyUri);
} else {
// fileOnlyUri: 'file:/opt/xt/api-209.jar'
return URI.create(fileOnlyUri);
}
}
List<Path> dirs = new ArrayList<>();
List<URI> jarFiles = new ArrayList<>();
for (URL resource : resources) {
if ("jar".equals(resource.getProtocol())) {
jarFiles.add(extractJarPath(resource));
} else {
dirs.add(Path.of(resource.toURI()));
}
}
Then reads jars
try (ZipInputStream zis = new ZipInputStream(new BufferedInputStream(Files.newInputStream(file)))) {
for (ZipEntry ze; (ze = zis.getNextEntry()) != null; ) {
Metadata
Metadata
Assignees
Labels
type: bugA general bug
Activity
philwebb commentedon Aug 31, 2026
Are you able to provide a sample application that reproduces the issue? Something that we can run and debug.
AbarnaaSree commentedon Aug 31, 2026
I’d like to investigate this. I’ll work on creating a minimal sample application that reproduces the
NestedByteChannel.read(ByteBuffer)behavior with a Spring Boot nested JAR, and I’ll share it here once I can reproduce the failure.snicoll commentedon Aug 31, 2026
@AbarnaaSree thanks but we're asking the sample to the OP.
[-]Buggy NestedByteChannel.read(ByteBuffer) prevents reading nested jar's[/-][+]Buggy NestedByteChannel.read(ByteBuffer) prevents reading nested jars[/+]turbanoff commentedon Sep 1, 2026
Here is the reproducer - https://github.com/turbanoff/spring-boot-bug-51515
wilkinsona commentedon Sep 1, 2026
Thanks for the sample, @turbanoff. I've reproduced the problem.
I noticed that the sample's using Spring Boot 3.5.16 and 3.5.x is no longer support. If I upgrade to 4.0.8, the problem still occurs. This means that we'll continue to investigate but please be aware that consuming any OSS fix will require an upgrade to Spring Boot 4.
wilkinsona commentedon Sep 1, 2026
Thanks, too, for the analysis, @turbanoff. I agree that
totalshould be returned, not0. Doing so fixes the sample such that it can process the full uber jar.[-]Buggy NestedByteChannel.read(ByteBuffer) prevents reading nested jars[/-][+]NestedByteChannel.read(ByteBuffer) incorrectly returns 0 from read(ByteBuffer) when buffer could not be filled[/+]Return correct total when read(ByteBuffer) cannot fill buffer
[-]NestedByteChannel.read(ByteBuffer) incorrectly returns 0 from read(ByteBuffer) when buffer could not be filled[/-][+]NestedByteChannel.read(ByteBuffer) incorrectly returns 0 when buffer could not be filled[/+]