Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8325590

Regression in round-tripping UTF-16 strings after JDK-8311906

    XMLWordPrintable

Details

    • b27
    • b10
    • Verified

    Backports

      Description

        I'm seeing a regression when writing a string to a file as UTF-16 and reading it back in using `Files.readString(String, Charset)` after JDK-8311906 (Improve robustness of String constructors with mutable array inputs).

        Repro:

        ```
        import static java.nio.charset.StandardCharsets.UTF_16;

        import java.io.IOException;
        import java.nio.file.Files;
        import java.nio.file.Path;
        import java.util.Arrays;

        public class Y {
          public static void main(String[] args) throws IOException {
            String original = "🤸";
            Path tmp = Files.createTempFile("tmp", ".txt");
            Files.writeString(tmp, original, UTF_16);
            String actual = Files.readString(tmp, UTF_16);
            System.err.printf("expected (%s), was (%s)\n", original, actual);
            System.err.printf("expected UTF_16 bytes: %s\n", Arrays.toString(original.getBytes(UTF_16)));
            System.err.printf("actual UTF_16 bytes: %s\n", Arrays.toString(actual.getBytes(UTF_16)));
          }
        }
        ```

        $ java -fullversion
        openjdk full version "21.0.2+13-58"
        $ java Y
        expected (🤸), was (🤸)
        expected UTF_16 bytes: [-2, -1, -40, 62, -35, 56]
        actual UTF_16 bytes: [-2, -1, -40, 62, -35, 56]

        $ java -fullversion
        openjdk full version "22+35-2369"
        $ java Y
        expected (🤸), was (>Ø8Ý)
        expected UTF_16 bytes: [-2, -1, -40, 62, -35, 56]
        actual UTF_16 bytes: [-2, -1, 0, 62, 0, -40, 0, 56, 0, -35]

        Attachments

          Issue Links

            Activity

              People

                rriggs Roger Riggs
                cushon Liam Miller-Cushon
                Votes:
                0 Vote for this issue
                Watchers:
                11 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: