Java 1.4: MalformedInputException is not thrown anymore?

Discussion in 'Java' started by Dima, Jul 14, 2004.

  1. Dima

    Dima Guest

    Hi,

    In Java 1.3 if I read an invalid UTF-8 data I get
    MalformedInputException.
    In Java 1.4 I get character 65533 and no exception.

    Why is what? Is it a bug? The new behaviour silently corrupts the data
    instead of throwing an exception.

    This is my test case:

    import java.io.*;

    public class test {

    public static void main(String[] args)
    throws Exception
    {
    int ch;
    Reader r = new InputStreamReader(new FileInputStream(args[0]),
    "UTF-8");
    while((ch = r.read()) >= 0) {
    System.out.println("char " + (char)ch + " " + (int)ch);
    }
    }
    }

    I put some Russian text in Cyrillic encoding and I try to read it as
    UTF-8.

    Java 1.3:
    /cygdrive/d/prj/utf8/>java test test.txt
    char t 116
    char e 101
    char s 115
    char t 116
    char : 58
    Exception in thread "main" sun.io.MalformedInputException
    at sun.io.ByteToCharUTF8.convert(ByteToCharUTF8.java:85)
    at java.io.InputStreamReader.convertInto(InputStreamReader.java:132)
    at java.io.InputStreamReader.fill(InputStreamReader.java:161)
    at java.io.InputStreamReader.read(InputStreamReader.java:244)
    at java.io.InputStreamReader.read(InputStreamReader.java:217)
    at test.main(test.java:10)

    Java 1.4:

    /cygdrive/d/prj/utf8/>c:/j2sdk1.4.2_04/bin/java test test.txt
    char t 116
    char e 101
    char s 115
    char t 116
    char : 58
    char 32
    char ? 65533
    char ? 65533
    char ? 65533
    char ? 65533
    char ? 65533
    char ? 65533
    char ? 65533
    char 32
    char
    10
    /cygdrive/d/prj/utf8/>


    Thanks and best regards,
    Dima.
    Dima, Jul 14, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tersia Ehlert

    HTTPS - Window. code not working anymore

    Tersia Ehlert, Jan 10, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    450
    =?Utf-8?B?QnJhZCBSb2JlcnRz?=
    Jan 10, 2005
  2. Gregoire Poncet
    Replies:
    0
    Views:
    354
    Gregoire Poncet
    Feb 2, 2006
  3. Dhruba Bandopadhyay

    ASP VIRTUAL keyword not working in ASP.NET anymore :S

    Dhruba Bandopadhyay, Mar 22, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    4,888
    Dhruba Bandopadhyay
    Mar 22, 2006
  4. Eric Lilja
    Replies:
    4
    Views:
    467
  5. musart
    Replies:
    12
    Views:
    797
    jorge
    Apr 5, 2013
Loading...

Share This Page