Uploaded image for project: 'Harmony'
  1. Harmony
  2. HARMONY-150

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • None
    • Classlib
    • 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;
        }
        }

      Attachments

        1. CharsetTest_Patch_150.txt
          5 kB
        2. Charset_patch_150.txt
          4 kB
          Paulex Yang

        Activity

          People

            tellison Tim Ellison
            richard_liang Richard Liang
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: