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

(cs) CharsetEncoder.encode() misses char after nonmapped one

XMLWordPrintable

    • generic
    • generic



      Name: elR10090 Date: 03/12/2001


      The implementation of the method encode() class java.nio.CharsetEncoder
      in the jdk1.4.0beta-b55 misses the character if the previous one in
      the input character buffer cannot be mapped to an equivalent byte
      sequence and the substitution occurs.

      The following simple test reveals this problem:

      Ctob log:

      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b55)
      Java HotSpot(TM) Client VM (build 1.4beta-B55, mixed mode)
      Charset: ISO-8859-1
      Chars from the source string: \u41 \u7ff \u42 \u43 \uffff \u44 \u45
      Bytes after encode: 0x41 0x3f 0x43 0x3f 0x45

      Ctob.java source:

      import java.nio.*;

      public class Ctob {

          final static String charsetName = "ISO-8859-1";
          final static String testString = "A\u07ffBC\uffffDE";

          public static void main(String args[]) throws Exception {
              Charset cs = Charset.forName(charsetName);
              CharsetEncoder encoder = cs.newEncoder();
              System.out.println("Charset: " + cs.name());

              byte[] bytes = new byte[64];
              ByteBuffer bb = ByteBuffer.wrap(bytes);

              System.out.print("Source string chars:" );
              char[] chars = testString.toCharArray();
              for (int i = 0; i < chars.length; i++) {
                  System.out.print(" \\u" + Integer.toHexString((int)chars[i]));
              }
              System.out.println("");

              CharBuffer cb = CharBuffer.wrap(testString);
              while (cb.hasRemaining()) {
                  encoder.encode(cb, bb, false);
              }
              encoder.flush(bb);
              bb.flip();
              int n = bb.remaining();
              System.out.print("Bytes after encoding:");
              for (int i = 0; i < n; i++) {
                  System.out.print(" 0x" + Integer.toHexString((int)bytes[i]));
              }
              System.out.println("");
              bb.clear();
          }
      }

      This bug affects the following testbase_nsk test:
          nsk/logging/Handler/setEncoding/stencd001
          
      I think also that the bug 4424300 has the same reason.
       
      ======================================================================

            mr Mark Reinhold
            latkinsunw Latkin Latkin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: