JDK-6348343 : REGRESSION: ClassCastException in JISAutoDetect.java on 1.4.2_10
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio.charsets
  • Affected Version: 1.4.2
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-11-10
  • Updated: 2011-02-16
  • Resolved: 2005-12-09
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.2_11 b02Fixed
Related Reports
Relates :  
Relates :  
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