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

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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: 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

        Hide
        tellison Tim Ellison added a comment -

        Verified by Richard

        Show
        tellison Tim Ellison added a comment - Verified by Richard
        Hide
        richard_liang Richard Liang added a comment -

        Thanks a lot. The fix looks good.

        Show
        richard_liang Richard Liang added a comment - Thanks a lot. The fix looks good.
        Hide
        tellison 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
        tellison 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.
        Hide
        richard_liang Richard Liang added a comment -

        Please try my patch. Thanks a lot!

        Show
        richard_liang Richard Liang added a comment - Please try my patch. Thanks a lot!
        Hide
        richard_liang 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 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; } }

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development