Harmony
  1. Harmony
  2. HARMONY-124

java.nio.charset.CharsetDecoder doesn't throw CoderMalfunctionError exception when decodeLoop threw unexpected exception.

    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

      public final CoderResult decode(ByteBuffer in, CharBuffer out, boolean endOfInput)
      As spec says, the method throws CoderMalfunctionError if an invocation of the decodeLoop method threw an unexpected exception.

      However, Harmony doesn't throws CoderMalfunctionError when decodeLoop method threw an unexpected exception.

      The following test cases pass on RI , but fail on Harmony.

      /*

      • Test malfunction decode(ByteBuffer)
        */
        public void testDecode_CoderMalfunctionError() throws Exception {
        MockMalfunctionCharset cs = new MockMalfunctionCharset("mock", null);
        try
        Unknown macro: { cs.newDecoder().onMalformedInput(CodingErrorAction.REPLACE) .onUnmappableCharacter(CodingErrorAction.REPLACE).decode(ByteBuffer.wrap(new byte[]{0x00,0x11}));
        fail("should throw CoderMalfunctionError");//NON-NLS-1$
        }catch(CoderMalfunctionError e){ //expected }
        }

        /*
        * Test malfunction decode(ByteBuffer)
        */
        public void testDecode_NoCoderMalfunctionError() throws Exception {
        MockMalfunctionCharset cs = new MockMalfunctionCharset("mock", null);
        try{
        cs.decode(ByteBuffer.wrap(new byte[]{0x00,0x11})); }

        catch(CoderMalfunctionError e)

        { fail("Charset.decode should return silently");//NON-NLS-1 }

        }
        /*

      • Mock charset class with malfunction decode & encode.
        */
        static final class MockMalfunctionCharset extends Charset {

      public MockMalfunctionCharset(String canonicalName, String[] aliases)

      { super(canonicalName, aliases); }

      public boolean contains(Charset cs)

      { return false; }

      public CharsetDecoder newDecoder()

      { return new MockMalfunctionDecoder(this); }

      public CharsetEncoder newEncoder()

      { return new MockMalfunctionEncoder(this); }

      }
      /*

      • Mock decoder. decodeLoop always throws unexpected exception.
        */
        static class MockMalfunctionDecoder extends java.nio.charset.CharsetDecoder {

      public MockMalfunctionDecoder(Charset cs)

      { super(cs, 1, 10); }

      protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out)

      { throw new BufferOverflowException(); }
      }
      /*
      * Mock encoder. encodeLoop always throws unexpected exception.
      */
      static class MockMalfunctionEncoder extends java.nio.charset.CharsetEncoder {

      public MockMalfunctionEncoder(Charset cs) {
      super(cs, 1, 3, new byte[] { (byte) '?' });
      }

      protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out) { throw new BufferOverflowException(); }

      }

      1. Charset_patch.txt
        0.7 kB
        Richard Liang
      2. CharsetDecoder_patch.txt
        1.0 kB
        Richard Liang

        Activity

        Tim Ellison made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Tim Ellison made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Richard Liang made changes -
        Field Original Value New Value
        Attachment Charset_patch.txt [ 12323361 ]
        Attachment CharsetDecoder_patch.txt [ 12323362 ]
        Richard Liang created issue -

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development