Harmony
  1. Harmony
  2. HARMONY-150

java.nio.charset.Charset.decode(in) doesn't use the same cached decoder.

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Classlib
    • Labels:
      None

      Description

      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
        Unknown macro: { 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

        Unknown macro: { if(caller != this){ // Another instance throw new RuntimeException(); } }

        return CoderResult.UNDERFLOW;
        }
        }

        Activity

        Richard Liang created issue -
        Hide
        Paulex Yang added a comment -

        Pls. try the patch. the patch for test will be created after test patches for JIRA 148 is applied. THX.

        Show
        Paulex Yang added a comment - Pls. try the patch. the patch for test will be created after test patches for JIRA 148 is applied. THX.
        Paulex Yang made changes -
        Field Original Value New Value
        Attachment Charset_patch_150.txt [ 12323908 ]
        Anonymous made changes -
        Attachment CharsetTest_Patch_150.txt [ 12324143 ]
        Hide
        Richard Liang added a comment -

        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.

        Show
        Richard Liang added a comment - 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.
        Tim Ellison made changes -
        Assignee Tim Ellison [ tellison ]
        Tim Ellison made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Hide
        Tim Ellison added a comment -

        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.

        Show
        Tim Ellison added a comment - 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.
        Tim Ellison made changes -
        Status In Progress [ 3 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Hide
        Richard Liang added a comment -

        Hi, Tim, the fix looks good Issue 182 (dupliated with this issue) is also resolved after applying this patch.
        Please close these two issues. Thanks a lot!

        Show
        Richard Liang added a comment - Hi, Tim, the fix looks good Issue 182 (dupliated with this issue) is also resolved after applying this patch. Please close these two issues. Thanks a lot!
        Hide
        Tim Ellison added a comment -

        Verified by Richard.

        Show
        Tim Ellison added a comment - Verified by Richard.
        Tim Ellison made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open In Progress In Progress
        27d 9h 35m 1 Tim Ellison 29/Mar/06 22:27
        In Progress In Progress Resolved Resolved
        2m 26s 1 Tim Ellison 29/Mar/06 22:29
        Resolved Resolved Closed Closed
        20h 26m 1 Tim Ellison 30/Mar/06 18:56

          People

          • Assignee:
            Tim Ellison
            Reporter:
            Richard Liang
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development