United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6348343 : REGRESSION: ClassCastException in JISAutoDetect.java on 1.4.2_10

Details
Type:
Bug
Submit Date:
2005-11-10
Status:
Resolved
Updated Date:
2011-02-16
Project Name:
JDK
Resolved Date:
2005-12-09
Component:
core-libs
OS:
windows_xp
Sub-Component:
java.nio.charsets
CPU:
x86
Priority:
P2
Resolution:
Fixed
Affected Versions:
1.4.2
Fixed Versions:
1.4.2_11 (b02)

Related Reports
Relates:
Relates:

Sub Tasks

Description
FULL PRODUCT VERSION :
java version "1.4.2_10"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_10-b03)
Java HotSpot(TM) Client VM (build 1.4.2_10-b03, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
When reading from a file contains Japanese character in SJIS or EUC_JP via FileInputStream with JISAutoDetect convertor, ClassCastException occurs in sun.nio.cs.ext.JISAutoDetect$Decoder.decodeLoop.

Here is a full stacktrace.
D:\SampleCode>java -showversion JISAutoDetectTest sjis.txt
java version "1.4.2_10"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_10-b03)
Java HotSpot(TM) Client VM (build 1.4.2_10-b03, mixed mode)

Exception in thread "main" java.lang.ClassCastException
        at sun.nio.cs.ext.JISAutoDetect$Decoder.decodeLoop(JISAutoDetect.java:12
6)
        at sun.nio.cs.ext.JISAutoDetect$Decoder.decodeLoop(JISAutoDetect.java:16
6)
        at java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:538)
        at sun.nio.cs.StreamDecoder$CharsetSD.implRead(StreamDecoder.java:442)
        at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:182)
        at java.io.InputStreamReader.read(InputStreamReader.java:167)
        at java.io.BufferedReader.fill(BufferedReader.java:136)
        at java.io.BufferedReader.readLine(BufferedReader.java:299)
        at java.io.BufferedReader.readLine(BufferedReader.java:362)
        at JISAutoDetectTest.main(JISAutoDetectTest.java:16)

This is not occurs on JDK 1.4.2_09 and the prior update release.
When reading from ascii file, It is not occurs.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create data file named "sjis.txt", which is written in Japanese character encoded SJIS
2. Compile the source code.
   javac JISAutoDetectTest.java
3. Run it
   java JISAutoDetectTest sjis.txt


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Don't occur the any exceptions, and just print the content of the file.
ACTUAL -
ClassCastException occurs.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.ClassCastException
        at sun.nio.cs.ext.JISAutoDetect$Decoder.decodeLoop(JISAutoDetect.java:12
6)
        at sun.nio.cs.ext.JISAutoDetect$Decoder.decodeLoop(JISAutoDetect.java:16
6)
        at java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:538)
        at sun.nio.cs.StreamDecoder$CharsetSD.implRead(StreamDecoder.java:442)
        at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:182)
        at java.io.InputStreamReader.read(InputStreamReader.java:167)
        at java.io.BufferedReader.fill(BufferedReader.java:136)
        at java.io.BufferedReader.readLine(BufferedReader.java:299)
        at java.io.BufferedReader.readLine(BufferedReader.java:362)
        at JISAutoDetectTest.main(JISAutoDetectTest.java:16)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
----- JISAutoDetecTest.java ----
import java.io.*;

public class JISAutoDetectTest {
  public static void main(String[] args) {
    if(args.length != 1) {
       System.out.println("usage : java JISAutoDetectTest <filename>");
       System.exit(0);
    }

    BufferedReader reader = null;

    try {
      File file = new File(args[0]);
      String line = null;
      reader = new BufferedReader(new InputStreamReader(new FileInputStream(file),"JISAutoDetect"));
      while ((line = reader.readLine()) != null ) {
        System.out.println(line);
      }
      reader.close();
    } catch (IOException e) {
      System.out.println(e);
    }
  }
}


---------- END SOURCE ----------

Release Regression From : 1.4.2_09
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

                                    

Comments
EVALUATION

This is the regression of
CR 6196407 - J2SE NIO: eucJP-open failed to be looked up
which was fixed in 1.4.2_08-b01 but was made visible due to
CR 5107263 - Worse performance of isSupported for JISAutoDetect (1.4.X)
which was fixed in 1.4.2_10-b02.
                                     
2005-11-15
EVALUATION

The MS932.Decoder does not implements "DelegatableDecoder", overlook when
backporting the JISAutoDetect class.
                                     
2005-11-11



Hardware and Software, Engineered to Work Together