Harmony
  1. Harmony
  2. HARMONY-173

java.nio.charset.CharsetEncoder.encode method does not reserve remaining bytes for next invocation.

    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

      Method
      public final CoderResult encode(CharBuffer in,
      ByteBuffer out,
      boolean endOfInput)
      Considering that there is a supplemental character which represents by 4 bytes like "\ud800\udc00", and it was divided into two input buffers. e.g. "\ud800" is at the end of input1 and the "\udc00" is at the begining of input2. when invoking the method encode(input1,out,false), it deals with "\ud800" as a malformed charactor and I think it should be reversed for next invocation like encode(input2,out,true).

      And it aslo must be handled correspondingly in method public final ByteBuffer encode(CharBuffer in).

      ===Test segment to reproduce the bug (fail on RI 5.0 and Harmony. I think it's also a bug for RI 5.0)

      CharsetEncoder encoder = Charset.forName("utf-8").newEncoder();
      CharBuffer in1 = CharBuffer.wrap("\ud800");
      CharBuffer in2 = CharBuffer.wrap("\udc00");
      ByteBuffer out = ByteBuffer.allocate(4);
      encoder.reset();
      CoderResult result = encoder.encode(in1, out, false);
      assertEquals(4, out.remaining());
      assertTrue(result.isUnderflow());
      result = encoder.encode(in2, out, true);
      assertEquals(0, out.remaining());
      assertTrue(result.isUnderflow());

      1. CharsetEncoder_patch_173.txt
        10 kB
        Paulex Yang
      2. CharsetEncoderTest_patch_173.txt
        1 kB
        Paulex Yang

        Activity

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

        pls. try the patches, thx.

        Show
        Paulex Yang added a comment - pls. try the patches, thx.
        Paulex Yang made changes -
        Field Original Value New Value
        Attachment CharsetEncoder_patch_173.txt [ 12323906 ]
        Attachment CharsetEncoderTest_patch_173.txt [ 12323907 ]
        Tim Ellison made changes -
        Assignee Tim Ellison [ tellison ]
        Tim Ellison made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Hide
        Tim Ellison added a comment -

        Thanks Richard,

        Patch applied to NIO_CHAR module java.nio.CharsetEncoder at repo revision 389784.

        Please check that the patch was applied as you expected.

        Show
        Tim Ellison added a comment - Thanks Richard, Patch applied to NIO_CHAR module java.nio.CharsetEncoder at repo revision 389784. Please check that the patch was applied as you expected.
        Tim Ellison made changes -
        Resolution Fixed [ 1 ]
        Status In Progress [ 3 ] Resolved [ 5 ]
        Hide
        Richard Liang added a comment -

        Hi, Tim, the fix looks good. Please close this issue, thanks!

        Show
        Richard Liang added a comment - Hi, Tim, the fix looks good. Please close this issue, thanks!
        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
        23d 1h 9m 1 Tim Ellison 29/Mar/06 22:32
        In Progress In Progress Resolved Resolved
        9m 4s 1 Tim Ellison 29/Mar/06 22:41
        Resolved Resolved Closed Closed
        20h 15m 1 Tim Ellison 30/Mar/06 18:57

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development