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

CharToByteUnicode.canConvert() does not work correctly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.2
    • core-libs
    • None

      Attached test case shows the problem, canConvert() returns "false"
      for legal unicode character, but it only fails the first time, the
      sequential calling rturns the correct result.

      Need either fix the problme in CharToByteConverter.canConvert() or
      make CharToByteUnicode have its own canConvert() implementation.


      import java.util.*;
      import java.nio.charset.*;
      import sun.io.*;

      public class TestUnicodeConverter {
          public static void main(String[] args) {
              try {
                  System.out.println("----------------------");
                  CharToByteConverter ctb = CharToByteConverter.getConverter("Unicode");
                  System.out.println("CharToByteConverter=" + ctb);
                  System.out.println("1: canConvert('A')=" + ctb.canConvert('A'));
                  System.out.println("2: canConvert('A')=" + ctb.canConvert('A'));
                  System.out.println("----------------------");
                  Charset cs = Charset.forName("UTF-16");
                  CharsetEncoder cse = cs.newEncoder();
                  System.out.println("Encoder=" + cse);
                  System.out.println("1: canEncode('A')=" + cse.canEncode('A'));
                  System.out.println("2: canEncode('A')=" + cse.canEncode('A'));
              }
              catch (Exception e) {
                  System.out.println("e=" + e);
              }
          }
      }

            ilittlesunw Ian Little (Inactive)
            sherman Xueming Shen
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: