harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Richard Liang (JIRA)" <j...@apache.org>
Subject [jira] Created: (HARMONY-150) java.nio.charset.Charset.decode(in) doesn't use the same cached decoder.
Date Thu, 02 Mar 2006 02:52:39 GMT
java.nio.charset.Charset.decode(in) doesn't use the same cached decoder.

         Key: HARMONY-150
         URL: http://issues.apache.org/jira/browse/HARMONY-150
     Project: Harmony
        Type: Bug
  Components: Classlib  
    Reporter: Richard Liang

java.nio.charset.Charset.decode(in) doesn't use the same cached decoder.
As spec says, "An invocation of this method upon a charset cs returns the same result as the
expression  cs.newDecoder() .onMalformedInput(CodingErrorAction.REPLACE) .onUnmappableCharacter(CodingErrorAction.REPLACE)
 .decode(bb); except that it is potentially more efficient because it can cache decoders between
successive invocations. "
RI always uses the same cached decoder (the same reference) for the same name charset. For
details, please refer to the test case below:
======== test case output =====
RI 5.0 passes the test case while Harmony fails.

======== test case===========
	 * test cached decoder
	public void testCachedDecoder() throws Exception{
		MockCachedCharset cs1 = new MockCachedCharset("CachedCharset",null);
		MockCachedCharset cs2 = new MockCachedCharset("CachedCharset",null);
		ByteBuffer in = ByteBuffer.wrap(new byte[]{0x00});
	 * Mock Charset for cached decoder test
	static class MockCachedCharset extends Charset{

		public MockCachedCharset(String canonicalName, String[] aliases){
			super(canonicalName, aliases);

		public boolean contains(Charset charset) {
			return false;

		public CharsetEncoder newEncoder() {
			return null;

		public CharsetDecoder newDecoder() {
			return new MockCachedDecoder(this);
	 * Mock decoder. Only one caller is permitted.
	static class MockCachedDecoder extends CharsetDecoder {
		static MockCachedDecoder caller = null;
		public MockCachedDecoder(Charset cs) {
			super(cs, 1, 10);

		 * Only one caller is permitted.
		 * If there's another caller, throw RuntimeException.
		protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) {
			if(null == caller){
				caller = this;
				if(caller != this){
					// Another instance 
					throw new RuntimeException();
			return CoderResult.UNDERFLOW;

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators:
For more information on JIRA, see:

View raw message