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

HKSCS encoder does not properly set the replacement character

XMLWordPrintable

    • Icon: Task Task
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 26
    • core-libs
    • None

      `sun.nio.cs.HKSCS.Encoder` extends from `sun.nio.cs.DoubleByte.Encoder`, which uses `DoubleByte.Encoder::repl` to store the replacement character. When `HKSCS.Encoder#implReplaceWith(byte[] newReplacement)` is called to set the replacement character, it only sets the private one, i.e., `HKSCS.Encoder::repl`. When `HKSCS.Encoder::encodeFromLatin1` gets called, it delegates to `DoubleByte.Encoder::encodeFromLatin1`, which uses `DoubleByte.Encoder::repl` and that does not match the `HKSCS.Encoder::repl`. Effectively, replacement character does not get picked up when `HKSCS.Encoder::encodeFromLatin1` is used.

      This anomaly can be reproduced with the following simple JTreg test:

      ```
      ArrayEncoder ae = (ArrayEncoder) Charset.forName("Big5-HKSCS").newEncoder()
                      .onMalformedInput(CodingErrorAction.REPLACE)
                      .onUnmappableCharacter(CodingErrorAction.REPLACE)
                      .replaceWith(new byte[]{65});
              var da = new byte[2];
              ae.encodeFromLatin1(new byte[]{0x2D, (byte) 0xD8}, 0, 2, da);
              if (da[0] != 0x2D || da[1] != 65) {
                  throw new RuntimeException("unexpected encoding result: [%d, %d]".formatted(da[0], da[1]));
              }
      ```

            vyazici Volkan Yazici
            vyazici Volkan Yazici
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: