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

Several codepoints in EUC_TW failed in roundtrip conversion

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 7
    • 6
    • core-libs
    • None

      The attached testcase shows the following codepoints failed in roundtrip
      conversion in EUC_TW.

       encode(4ea0)=[a7,a8,a7,c2]: bb.pos=2, decode(a7,a8,a7,c2)=fffd, cb.pos=1
       encode(4ea1)=[c4,c1,a7,c2]: bb.pos=2, decode(c4,c1,a7,c2)=fffd, cb.pos=1
       encode(4ea2)=[c4,ed,a7,c2]: bb.pos=2, decode(c4,ed,a7,c2)=fffd, cb.pos=1
       encode(4ea3)=[8e,a3,a1,c7]: bb.pos=4, decode(8e,a3,a1,c7)=6495, cb.pos=1
       encode(51ab)=[a7,af,c6,dc]: bb.pos=2, decode(a7,af,c6,dc)=fffd, cb.pos=1
       encode(51ac)=[c5,f6,c6,dc]: bb.pos=2, decode(c5,f6,c6,dc)=fffd, cb.pos=1
       encode(51ad)=[8e,a4,a1,de]: bb.pos=4, decode(8e,a4,a1,de)=971c, cb.pos=1
       encode(52f9)=[a7,b4,e5,ba]: bb.pos=2, decode(a7,b4,e5,ba)=fffd, cb.pos=1
       encode(52fa)=[c4,c4,e5,ba]: bb.pos=2, decode(c4,c4,e5,ba)=fffd, cb.pos=1
       encode(52fb)=[c5,a4,e5,ba]: bb.pos=2, decode(c5,a4,e5,ba)=4e03, cb.pos=1
      Total roundtrip failed 10


      import java.nio.*;
      import java.nio.charset.*;

      public class Bug_EUCTW {
          public static void main(String[] argv) throws Exception {
              Charset cs = Charset.forName("EUC_TW");
              CharsetEncoder enc = cs.newEncoder()
      .onMalformedInput(CodingErrorAction.REPLACE)
      .onUnmappableCharacter(CodingErrorAction.REPLACE);
      CharsetDecoder dec = cs.newDecoder()
      .onMalformedInput(CodingErrorAction.REPLACE)
      .onUnmappableCharacter(CodingErrorAction.REPLACE);

              byte[] ba = new byte[4];
              char[] ca = new char[1];
              CharBuffer cb = CharBuffer.wrap(ca);
      ByteBuffer bb = ByteBuffer.wrap(ba);
              CoderResult cr = null;
              int failed = 0;
              for (char c = '\u0000'; c < '\uffff'; c++) {
                  if (enc.canEncode(c)) {
                      cb.clear();
      bb.clear();
      ca[0] = c;
      cr = enc.encode(cb, bb, true);
      ca[0] = 0;
      bb.flip();cb.clear();
      cr = dec.decode(bb, cb, true);
                      if (ca[0] != c) {
                          failed++;
      System.out.printf(" encode(%x)=[%x,%x,%x,%x]: bb.pos=%d, decode(%x,%x,%x,%x)=%x, cb.pos=%d\n",
      c&0xffff,
      ba[0]&0xff, ba[1]&0xff, ba[2]&0xff, ba[3]&0xff,
      bb.limit(),
      ba[0]&0xff, ba[1]&0xff, ba[2]&0xff, ba[3]&0xff,
      ca[0]&0xffff, cb.position());
      }
      }
      }
              if (failed != 0) {
                  System.out.printf("Total roundtrip failed %d\n", failed);
              } else
      System.out.printf(" All Passed!");
          }
      }

      ###@###.### 2005-2-16 08:54:31 GMT

            sherman Xueming Shen
            sherman Xueming Shen
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: