RFR: 8347712: IllegalStateException on multithreaded ZipFile access with non-UTF8 charset [v2]

Eirik Bjørsnøs eirbjo at openjdk.org
Sun Mar 23 10:48:13 UTC 2025


On Sun, 23 Mar 2025 08:34:18 GMT, Eirik Bjørsnøs <eirbjo at openjdk.org> wrote:

> This seems like a separate bug, independent of the concurrency concerns described JDK-8347712.

Consider the following test, which when added to `ZipCoding.java` fails in master but succeeds in this PR:


/**
 * Verifies that opening a ZipFile with an incorrect charset does not
 * prevent a later opening of the same file using the correct charset.
 *
 * This may happen if the two ZipFile instances have identical
 * ZipFile.Source.Key, thus mapping to the same Source instance.
 *
 * @throws IOException if an unexpected I/O error occurs
 */
@Test
public void differentNonUTF8Charsets() throws IOException {
    // Using ISO-8859-15 and ISO-8859-1 here, since they are similar
    // encodings with different characters for some bytes

    // The byte 0xA4 is "Euro sign" in 8859-15, "Currency sign (generic)" in 8859-1
    String euroSign = "\u20AC";
    String currencySign = "\u00A4";

    // Create a ZIP, encoded in ISO-8859-15
    byte[] zip = createZIP("ISO-8859-15", euroSign, euroSign);
    Path f = Path.of("zf-non-utf.zip");
    Files.write(f, zip);

    // Open a ZipFile instance using (incorrect) encoding ISO-8859-1
    // Then open a ZipFile instance using (correct) encoding ISO-8859-15
    try (ZipFile incorrect = new ZipFile(f.toFile(), StandardCharsets.ISO_8859_1);
         ZipFile correct = new ZipFile(f.toFile(), Charset.forName("ISO-8859-15"))) {

        // Correct encoding should resolve euro sign
        assertNotNull(correct.getEntry(euroSign));
        // Correct encoding should not resolve currency sign
        assertNull(correct.getEntry(currencySign));

        // Incorrect encoding should resolve currency sign
        assertNotNull(incorrect.getEntry(currencySign));
        // Incorrect encoding should not resolve euro sign
        assertNull(incorrect.getEntry(euroSign));
    }
}

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/23986#discussion_r2009075004


More information about the core-libs-dev mailing list