harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tim Ellison (JIRA)" <j...@apache.org>
Subject [jira] Resolved: (HARMONY-150) java.nio.charset.Charset.decode(in) doesn't use the same cached decoder.
Date Wed, 29 Mar 2006 12:31:19 GMT
     [ http://issues.apache.org/jira/browse/HARMONY-150?page=all ]
     
Tim Ellison resolved HARMONY-150:
---------------------------------

    Resolution: Fixed

Thanks Richard,

Patch applied to NIO_CHAR module java.nio.charset.Charset at repo revision 389782.

Please check that the patch was applied as you expected.


> 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
>     Assignee: Tim Ellison
>  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


Mime
View raw message