Skip to content

JarEntry.getComment() returns incorrect result from NestedJarFile instances #39166

@ql2023

Description

@ql2023

spring-boot-loader 3.2.0

test code:

public class NestedJarFileTests {

    public static void main(String[] args) throws IOException {

        try (JarArchiveOutputStream jar = new JarArchiveOutputStream(new FileOutputStream("app.jar"))) {
            jar.putArchiveEntry(new JarArchiveEntry("BOOT-INF"));
            jar.closeArchiveEntry();

            jar.putArchiveEntry(new JarArchiveEntry("BOOT-INF/classes/"));
            jar.closeArchiveEntry();
            for (int i = 0; i < 5; i++) {
                JarArchiveEntry entry = new JarArchiveEntry("BOOT-INF/classes/T" + i + ".class");
                entry.setComment("T" + i);
                jar.putArchiveEntry(entry);
                jar.write(UUID.randomUUID().toString().getBytes());
                jar.closeArchiveEntry();
            }
        }

        try (JarFile jf = new JarFile(new File("app.jar"))) {
            Enumeration<JarEntry> entries = jf.entries();
            while (entries.hasMoreElements()) {
                JarEntry entry = entries.nextElement();
                System.out.printf("entry=%s, comment=%s%n", entry.getName(), entry.getComment());
            }
        }

        try (NestedJarFile jf = new NestedJarFile(new File("app.jar"), "BOOT-INF/classes/")) {
            Enumeration<JarEntry> entries = jf.entries();
            while (entries.hasMoreElements()) {
                JarEntry entry = entries.nextElement();
                System.out.printf("entry=%s, comment=%s%n", entry.getName(), entry.getComment());
            }
        }
    }
}

output:

entry=BOOT-INF, comment=null
entry=BOOT-INF/classes/, comment=null
entry=BOOT-INF/classes/T0.class, comment=T0
entry=BOOT-INF/classes/T1.class, comment=T1
entry=BOOT-INF/classes/T2.class, comment=T2
entry=BOOT-INF/classes/T3.class, comment=T3
entry=BOOT-INF/classes/T4.class, comment=T4
entry=T0.class, comment=�1
entry=T1.class, comment=�1
entry=T2.class, comment=�1
entry=T3.class, comment=�1
entry=T4.class, comment=�1

Metadata

Metadata

Assignees

Labels

type: regressionA regression from a previous release

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions