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

(cs) decode() of EUC_TW.Decoder and DoubleByteDecoder return wrong CoderResult for unmappable char

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 6
    • 6
    • core-libs
    • None

      decode() of EUC_TW.Decoder and DoubleByteDecoder return CoderResult for unmappable double byte character with wrong "length" value. See test case
      below.

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

      public class TestUnmappableForLength {
          public static void main(String[] argv) throws CharacterCodingException {
                  byte[] ba = {(byte)0xa2, (byte)0xff};
                  //EUC_TW has its own decodeArrayLoop()
      testDecode("EUC_TW", ba, 2);

                  //EUC_CN uses DoubleByteDecoder's decodeArrayLoop()
                  testDecode("EUC_CN", ba, 2);
          }

          static void testDecode(String csName, byte[] ba, int expected)
      throws CharacterCodingException
          {
              try {
                  CoderResult cr = Charset
      .forName(csName)
      .newDecoder()
      .decode(ByteBuffer.wrap(ba), CharBuffer.allocate(4), true);
                  if (cr.isUnmappable() && cr.length() != expected) {
      throw new CharacterCodingException();
                  }
      } catch (IllegalArgumentException x){
      x.printStackTrace();
      }
          }

      }

      ###@###.### 2005-2-09 18:09:10 GMT

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: