Harmony
  1. Harmony
  2. HARMONY-141

Constructors of java.nio.charset.CharsetEncoder do not validate arguments

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      Constructors of java.nio.charset.CharsetEncoder should throw IllegalArgumentException when averageBytesPerChar exceeds maxBytesPerChar.

        Activity

        Hide
        Richard Liang added a comment -

        Here are the test cases which will pass on RI but fail on Harmony.

        public void testConstructorIlegalAverageBytesPerChar() {
        try

        { Charset cs = Charset.forName("UTF-8"); //$NON-NLS-1$ CharsetEncoder encoder = new MockCharsetEncoderForHarmony141(cs, 1.1f, 1); fail("Should throw IllegalArgumentException."); //$NON-NLS-1$ }

        catch (IllegalArgumentException e)

        { // expected }
        }

        public void testConstructorIlegalAverageBytesPerChar2() {
        try {
        Charset cs = Charset.forName("ISO8859-1"); //$NON-NLS-1$
        CharsetEncoder encoder = new MockCharsetEncoderForHarmony141(cs, 1.1f, 1,
        new byte[] { 0x1a});
        fail("Should throw IllegalArgumentException."); //$NON-NLS-1$
        } catch (IllegalArgumentException e) { // expected }

        }

        public static class MockCharsetEncoderForHarmony141 extends CharsetEncoder {

        protected MockCharsetEncoderForHarmony141(Charset cs, float averageBytesPerChar,
        float maxBytesPerChar)

        { super(cs, averageBytesPerChar, maxBytesPerChar); }

        public MockCharsetEncoderForHarmony141(Charset cs, float averageBytesPerChar,
        float maxBytesPerChar, byte[] replacement)

        { super(cs, averageBytesPerChar, maxBytesPerChar, replacement); }

        protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out)

        { return null; }

        }

        Show
        Richard Liang added a comment - Here are the test cases which will pass on RI but fail on Harmony. public void testConstructorIlegalAverageBytesPerChar() { try { Charset cs = Charset.forName("UTF-8"); //$NON-NLS-1$ CharsetEncoder encoder = new MockCharsetEncoderForHarmony141(cs, 1.1f, 1); fail("Should throw IllegalArgumentException."); //$NON-NLS-1$ } catch (IllegalArgumentException e) { // expected } } public void testConstructorIlegalAverageBytesPerChar2() { try { Charset cs = Charset.forName("ISO8859-1"); //$NON-NLS-1$ CharsetEncoder encoder = new MockCharsetEncoderForHarmony141(cs, 1.1f, 1, new byte[] { 0x1a}); fail("Should throw IllegalArgumentException."); //$NON-NLS-1$ } catch (IllegalArgumentException e) { // expected } } public static class MockCharsetEncoderForHarmony141 extends CharsetEncoder { protected MockCharsetEncoderForHarmony141(Charset cs, float averageBytesPerChar, float maxBytesPerChar) { super(cs, averageBytesPerChar, maxBytesPerChar); } public MockCharsetEncoderForHarmony141(Charset cs, float averageBytesPerChar, float maxBytesPerChar, byte[] replacement) { super(cs, averageBytesPerChar, maxBytesPerChar, replacement); } protected CoderResult encodeLoop(CharBuffer in, ByteBuffer 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.
        Hide
        Richard Liang added a comment -

        Again I forget something:

        The test cases pass on RI 5.0 and fail on Harmony and RI 1.4.2. This may be an improvement of RI 5.0

        Show
        Richard Liang added a comment - Again I forget something: The test cases pass on RI 5.0 and fail on Harmony and RI 1.4.2. This may be an improvement of RI 5.0
        Hide
        Tim Ellison added a comment -

        Richard,

        Thanks for the patch. Applied to NIO_CHAR module at repo revision 382383 with minor modification to the test case (to bring naming in line with test case conventions) and removing invlid NON-NLS tags.

        Please check that the problem is fully resolved.

        Show
        Tim Ellison added a comment - Richard, Thanks for the patch. Applied to NIO_CHAR module at repo revision 382383 with minor modification to the test case (to bring naming in line with test case conventions) and removing invlid NON-NLS tags. Please check that the problem is fully resolved.
        Hide
        Richard Liang added a comment -

        Tim,
        The fix is good. Please close this issue. Thanks a lot.

        Show
        Richard Liang added a comment - Tim, The fix is good. Please close this issue. Thanks a lot.
        Hide
        Tim Ellison added a comment -

        Verified by Richard

        Show
        Tim Ellison added a comment - Verified by Richard

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development