Java 1.4: MalformedInputException is not thrown anymore?

D

Dima

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top