Harmony
  1. Harmony
  2. HARMONY-142

java.nio.charset.CharsetDecoder constructor doesn't throw IllegalArgumentException when averageCharsPerByte is greater than maxCharsPerByte.

    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

      As spec says, constructor throws IllegalArgumentException when parameters are illegal. It should be considered as illegal parameters when averageCharsPerByte is greater than maxCharsPerByte.

        Activity

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

        Here is the testcases which pass on RI 5.0 and fail on both Haromny and RI 1.4.2

        Thanks a lot.

        /*

        • test constructor: averBytesPerChar > maxBytesPerChar
          */
          public void testConstructorIlegalAverageBytesPerChar()
          Unknown macro: { try { Charset cs = Charset.forName("UTF-8"); //$NON-NLS-1$ CharsetDecoder decoder = new MockCharsetDecoderForHarmony142(cs, 1.1f, 1); fail("Should throw IllegalArgumentException."); //$NON-NLS-1$ } catch (IllegalArgumentException e) { // expected } }

        /*

        • MockCharsetDecoderForHarmony142: for constructor test
          */
          static class MockCharsetDecoderForHarmony142 extends CharsetDecoder {
          protected MockCharsetDecoderForHarmony142(Charset cs,
          float averageBytesPerChar, float maxBytesPerChar) { super(cs, averageBytesPerChar, maxBytesPerChar); }

        protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out)

        { return null; }

        }

        Show
        Richard Liang added a comment - Here is the testcases which pass on RI 5.0 and fail on both Haromny and RI 1.4.2 Thanks a lot. /* test constructor: averBytesPerChar > maxBytesPerChar */ public void testConstructorIlegalAverageBytesPerChar() Unknown macro: { try { Charset cs = Charset.forName("UTF-8"); //$NON-NLS-1$ CharsetDecoder decoder = new MockCharsetDecoderForHarmony142(cs, 1.1f, 1); fail("Should throw IllegalArgumentException."); //$NON-NLS-1$ } catch (IllegalArgumentException e) { // expected } } /* MockCharsetDecoderForHarmony142: for constructor test */ static class MockCharsetDecoderForHarmony142 extends CharsetDecoder { protected MockCharsetDecoderForHarmony142(Charset cs, float averageBytesPerChar, float maxBytesPerChar) { super(cs, averageBytesPerChar, maxBytesPerChar); } protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) { return null; } }
        Hide
        Richard Liang added a comment -

        Please try my patch. Thanks a lot!

        Show
        Richard Liang added a comment - Please try my patch. Thanks a lot!
        Richard Liang made changes -
        Field Original Value New Value
        Attachment CharsetDecoder_patch.txt [ 12323605 ]
        Tim Ellison made changes -
        Assignee Tim Ellison [ tellison ]
        Tim Ellison made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Hide
        Tim Ellison added a comment -

        Richard,

        Thanks for the patch, applied to NIO_CHAR module java.nio.charset.CharsetDecoder at repo revision 382380.

        I made a couple of minor modifications to rename the test method in keeping with the tests naming convention, and unmark the exception description as NON-NLS because it should in fact be NLS'd via the Msg type.

        Please check that this fix fully resolves your problem.

        Show
        Tim Ellison added a comment - Richard, Thanks for the patch, applied to NIO_CHAR module java.nio.charset.CharsetDecoder at repo revision 382380. I made a couple of minor modifications to rename the test method in keeping with the tests naming convention, and unmark the exception description as NON-NLS because it should in fact be NLS'd via the Msg type. Please check that this fix fully resolves your problem.
        Tim Ellison made changes -
        Status In Progress [ 3 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Hide
        Richard Liang added a comment -

        Thanks a lot. The fix looks good.

        Show
        Richard Liang added a comment - Thanks a lot. The fix looks good.
        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
        1d 10h 56m 1 Tim Ellison 02/Mar/06 22:38
        In Progress In Progress Resolved Resolved
        3m 26s 1 Tim Ellison 02/Mar/06 22:42
        Resolved Resolved Closed Closed
        23h 5m 1 Tim Ellison 03/Mar/06 21:47

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development