JDK-6226510 : ISO-2022-JP encoder's reset() method noop; should revert to ASCII
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio.charsets
  • Affected Version: 6
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2005-02-08
  • Updated: 2010-04-02
  • Resolved: 2005-02-19
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.
JDK 6
6 b25Fixed
Related Reports
Relates :  
Description
The self-explanatory program below should not throw an exception

---------------------------------------------------------------------
import java.nio.*;
import java.nio.charset.*;

class Reset {

    public static void main(String[] args) throws Exception {
	if (! (encode(true).equals(encode(false))))
	    throw new Exception("Mismatch!");
    }

    static String encode(boolean reuseEncoder) {
	String s = "\u3042\u3043\u3044";

	CharsetEncoder e = Charset.forName("ISO-2022-JP").newEncoder();

	if (reuseEncoder) {
	    // I'm turning japanese. Yes I'm turning japanese.  Yes I think so!
	    e.encode(CharBuffer.wrap(s), ByteBuffer.allocate(64), true);

	    // Should put encoder back into ASCII mode
	    e.reset();
	}

	ByteBuffer bb = ByteBuffer.allocate(64);
	e.encode(CharBuffer.wrap(s), bb, true);
	e.flush(bb);
	bb.flip();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < bb.limit(); i++)
	    sb.append(String.format("%02x ", bb.get(i)));
	System.out.println(sb);
	return sb.toString();
    }
}
---------------------------------------------------------------------
###@###.### 2005-2-08 03:13:25 GMT

Comments
EVALUATION Yup. ###@###.### 2005-2-08 03:13:26 GMT
08-02-2005

SUGGESTED FIX --- /tmp/geta19882 2005-02-07 18:02:00.598304800 -0800 +++ ISO2022_JP.java 2005-02-07 18:01:17.742233000 -0800 @@ -351,28 +351,28 @@ private int currentMode = ASCII; private Encoder(Charset cs) { super(cs, 4.0f, 8.0f); } protected void implReset() { - int currentMode = ASCII; + currentMode = ASCII; } ###@###.### 2005-2-08 03:13:26 GMT
08-02-2005