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

Invalid UTF8 data doesn't produce sun.io.MalformedInputException

XMLWordPrintable

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

      Name: dk106046 Date: 08/14/2002

      Instead of ?sun.io.MalformedInputException?, garbage is displayed
      in the console and in the popup frame while reading bad utf8data.

      Problem is seen on: Sun 1.4.0_01-b03 and Sun 1.4.1-beta-b14
      Works fine with: Sun 1.3.1_04-b02 and IBM 131 cn131-20020710

      Testcase:

      //--------------------------------------------------------------------
      import java.io.*;
      import javax.swing.*;

      public class ReadUTF8
      {
          public static void main(String[] argv)
          {
              JFrame jf=new JFrame();
              JPanel p=new JPanel();
              JTextArea t=new JTextArea(10,80);
              p.add(t);
              jf.getContentPane().add(p);
              jf.setSize(800,300);
              jf.show();
              System.out.println(argv[0]);
              try
              {
                  File f=new File(argv[0]);
                  BufferedReader i=new BufferedReader(
                      new InputStreamReader(
                          new FileInputStream(f),"UTF-8"));
                  String s=i.readLine();
                  while(s!=null)
                  {
                      System.out.println(s);
                      s=i.readLine();
                      t.append(s);
                      t.append("\r\n");
                  }
              }
              catch(Exception e)
              {
                  System.out.println(e);
              }
          }
      }
      //--------------------------------------------------------------------

      [ "testutf8.txt" and "testansi.txt" are available via contact email ]

      'java ReadUTF8 testutf8.txt' displays belarussian correctly in the frame

      'java ReadUTF8 testansi.txt' results in garbage displaying in the
      console and in the popup frame.

      This is INCORRECT behavior. Once the utf8 decoder encounters invalid data, the read should exit with sun.io.MalformedInputException, not continue and corrupt the data.
      ======================================================================

            ilittlesunw Ian Little (Inactive)
            dkorbel David Korbel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: