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

        Tim Ellison made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Tim Ellison made changes -
        Status In Progress [ 3 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Tim Ellison made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Tim Ellison made changes -
        Assignee Tim Ellison [ tellison ]
        Anonymous made changes -
        Attachment CharsetTest_Patch_150.txt [ 12324143 ]
        Paulex Yang made changes -
        Field Original Value New Value
        Attachment Charset_patch_150.txt [ 12323908 ]
        Richard Liang created issue -

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development