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

(cs) Bogus "converter malfunction" errors from String constructors

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 1.4.0
    • 1.4.0
    • core-libs
    • None
    • beta3
    • generic
    • generic

      When running my converter test program I got a large number of errors in
      JDK 1.4 due to a bug in the String constructor. When malformed byte
      sequence is given, the code in java.lang.StringCoding.java thows an Error
      with the text "Converter malfunction". The new class Error is designed for
      cases of internal JVM errors and should not be thrown for cases of bad
      input which the app may well want to check for. In all previous versions
      of Java, and in the String.getBytes() method malformed sequences are
      ignored and there is no exception (or Error) thrown.

      The code at line 123 of StringCoding.java needs to set the count based on
      nextCharIndex() as is done in String.java in JDK 1.3 (about line 862). A
      much better solution would be to do what is done in the String.getBytes()
      and restart the convert after ignoring the malformed input. This matches
      what is done when using the nio converters.


      public class StringErrorTest {
           public static void main (String[] args) {
               byte [] b = {(byte)0x82};
               String s;
               try {
                   s = new String(b, "Cp950");
               } catch (Exception e) {
                   e.printStackTrace(System.err);
                   s = "<exception>";
               }
               System.out.println("Convert = " + s);
           }
      }

      >java StringErrorTest
      Exception in thread "main" java.lang.Error: Converter malfunction:
      sun.io.ByteToCharCp950
              at java.lang.StringCoding$ConverterSD.decode(StringCoding.java:123)
              at java.lang.StringCoding.decode(StringCoding.java:189)
              at java.lang.String.<init>(String.java:325)
              at java.lang.String.<init>(String.java:346)
              at StringErrorTest.main(StringErrorTest.java:6)
      Caused by: sun.io.MalformedInputException
              at sun.io.ByteToCharDBCS_ASCII.flush(ByteToCharDBCS_ASCII.java:38)
              at java.lang.StringCoding$ConverterSD.decode(StringCoding.java:120)
              ... 4 more

            mr Mark Reinhold
            mr Mark Reinhold
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: