Return-Path: Delivered-To: apmail-incubator-harmony-dev-archive@www.apache.org Received: (qmail 650 invoked from network); 7 Mar 2006 06:12:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 7 Mar 2006 06:12:03 -0000 Received: (qmail 76496 invoked by uid 500); 7 Mar 2006 06:12:00 -0000 Delivered-To: apmail-incubator-harmony-dev-archive@incubator.apache.org Received: (qmail 76442 invoked by uid 500); 7 Mar 2006 06:12:00 -0000 Mailing-List: contact harmony-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: harmony-dev@incubator.apache.org Delivered-To: mailing list harmony-dev@incubator.apache.org Received: (qmail 76431 invoked by uid 99); 7 Mar 2006 06:12:00 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Mar 2006 22:12:00 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received: from [192.87.106.226] (HELO ajax) (192.87.106.226) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Mar 2006 22:11:59 -0800 Received: from ajax (localhost.localdomain [127.0.0.1]) by ajax (Postfix) with ESMTP id EB3846ACA9 for ; Tue, 7 Mar 2006 06:11:38 +0000 (GMT) Message-ID: <2004251201.1141711898960.JavaMail.jira@ajax> Date: Tue, 7 Mar 2006 06:11:38 +0000 (GMT) From: "Richard Liang (JIRA)" To: harmony-dev@incubator.apache.org Subject: [jira] Created: (HARMONY-182) java.nio.charset.Charset.encode(in) doesn't use the same cached encoder. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N java.nio.charset.Charset.encode(in) doesn't use the same cached encoder. ------------------------------------------------------------------------ Key: HARMONY-182 URL: http://issues.apache.org/jira/browse/HARMONY-182 Project: Harmony Type: Bug Reporter: Richard Liang As spec says, "An invocation of this method upon a charset cs returns the same result as the expression cs.newEncoder() .onMalformedInput(CodingErrorAction.REPLACE) .onUnmappableCharacter(CodingErrorAction.REPLACE) .decode(bb); except that it is potentially more efficient because it can cache encoders between successive invocations. " RI always uses the same cached encoder (the same reference) for the charsets with same name. The following test case pass on RI 5.0, but fail on Harmony. /* * test cached encoder */ public void testCachedEncoder() throws Exception { MockCachedCharset cs1 = new MockCachedCharset("CachedCharset", null); MockCachedCharset cs2 = new MockCachedCharset("CachedCharset", null); CharBuffer in = CharBuffer.wrap("A"); cs1.encode(in); in.flip(); cs2.encode(in); } /* * Mock Charset for cached encoder test */ static class MockCachedCharset extends Charset { public MockCachedCharset(String canonicalName, String[] aliases) { super(canonicalName, aliases); } public boolean contains(Charset charset) { return false; } public CharsetDecoder newDecoder() { return new MockCachedDecoder(this); } public CharsetEncoder newEncoder() { return new MockCachedEncoder(this); } } /* * Mock encoder. Only one caller is permitted. */ static class MockCachedEncoder extends CharsetEncoder { static MockCachedEncoder caller = null; public MockCachedEncoder(Charset cs) { super(cs, 1, 10); } /* * Only one caller is permitted. */ protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out) { if (null == caller) { caller = this; } else { if (caller != this) { // Another instance fail("should use same instance"); } } return CoderResult.UNDERFLOW; } } /* * Mock decoder. */ static class MockCachedDecoder extends CharsetDecoder { static MockCachedEncoder caller = null; public MockCachedDecoder(Charset cs) { super(cs, 1, 10); } protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) { in.position(in.limit()); 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