You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Richard Liang (JIRA)" <ji...@apache.org> on 2006/03/14 06:34:52 UTC

[jira] Commented: (HARMONY-150) java.nio.charset.Charset.decode(in) doesn't use the same cached decoder.

    [ http://issues.apache.org/jira/browse/HARMONY-150?page=comments#action_12370306 ] 

Richard Liang commented on HARMONY-150:
---------------------------------------

I've attached the test cases in patch format. To apply the patch, simply click "team"->"apply patch ...". 
Would you please have a try ? Thank you very much.

Notes: This patch also includes test cases for JIRA #182(http://issues.apache.org/jira/browse/HARMONY-182), which is duplicated with this issue.

> 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
>  Attachments: CharsetTest_Patch_150.txt, Charset_patch_150.txt
>
> 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});
> 		cs1.decode(in);
> 		in.flip();
> 		cs2.decode(in);
> 		in.flip();
> 	}
> 	/*
> 	 * 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;
> 			}else{
> 				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:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira