CharToByteUnicode.canConvert() does not work correctly

XMLWordPrintable

    • Type: Bug
    • Resolution: Duplicate
    • Priority: P4
    • None
    • Affects Version/s: 1.4.2
    • Component/s: 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);
              }
          }
      }

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: