Harmony
  1. Harmony
  2. HARMONY-6408

[classlib][luni]OutputStreamWriterTest got java.nio.BufferOverflowException

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 5.0M12
    • Component/s: Classlib
    • Labels:
      None
    • Patch Info:
      Patch Available

      Description

      Following is the exception trace:
      java.nio.BufferOverflowException

      java.nio.charset.CoderMalfunctionError: java.nio.BufferOverflowException
      at java.nio.charset.CharsetEncoder.encode(CharsetEncoder.java:450)
      at java.io.OutputStreamWriter.convert(OutputStreamWriter.java:237)
      at java.io.OutputStreamWriter.write(OutputStreamWriter.java:232)
      at java.io.Writer.write(Writer.java:98)
      at org.apache.harmony.luni.tests.java.io.OutputStreamWriterTest.testHandleEarlyEOFChar_1(OutputStreamWriterTest.java:416)
      at java.lang.reflect.VMReflection.invokeMethod(VMReflection.java)
      Caused by: java.nio.BufferOverflowException
      at java.nio.ReadWriteHeapByteBuffer.put(ReadWriteHeapByteBuffer.java:97)
      at org.apache.harmony.niochar.charset.additional.GB2312$Encoder.encodeLoop(GB2312.java:297)
      at java.nio.charset.CharsetEncoder.encode(CharsetEncoder.java:448)
      at java.io.OutputStreamWriter.convert(OutputStreamWriter.java:237)

      In OutputStreamWriter's constructor using the default character encoding, on my machine, it is GB2312.
      If I set the encoder to "ISO8859_1" the test passed.
      So I think most of the members from China will got this error.

        Activity

        Hide
        Ray Chen added a comment -

        Hi,
        I have investigated this issue, found that if uses IBM vm, the default
        encoding on my machine is GB18030 while using DRLVM it is GB2312.
        I searched GB18030, found it on http://en.wikipedia.org/wiki/GB_18030
        which says GB2312 should be replaced with GB18030.

        The question is why different vm got different default file encoding?
        It seems that System.ensureProperties() got the default file encoding,
        in this function calls a static native method named "getEncoding()".
        But I can not find this native funtion in my classlib working copy.
        Does anyone know about this? Is this a classlib bug or vm bug?


        Regards,

        Ray Chen

        Show
        Ray Chen added a comment - Hi, I have investigated this issue, found that if uses IBM vm, the default encoding on my machine is GB18030 while using DRLVM it is GB2312. I searched GB18030, found it on http://en.wikipedia.org/wiki/GB_18030 which says GB2312 should be replaced with GB18030. The question is why different vm got different default file encoding? It seems that System.ensureProperties() got the default file encoding, in this function calls a static native method named "getEncoding()". But I can not find this native funtion in my classlib working copy. Does anyone know about this? Is this a classlib bug or vm bug? – Regards, Ray Chen
        Hide
        Ray Chen added a comment -

        In the patch, I do three things:

        1. Mapping 936 to GBK instead of GB2312 according to Windows Control Panel->Regional and Language options, which is as same as RI do.

        2. Fix one bug in GBK encoding

        3. Fix one bug in GB2312 encoding, both of them should minus bbRemaining by one after putting one byte into the buffer.

        I have ran the nio, nio_char and luni test, no regression.

        Show
        Ray Chen added a comment - In the patch, I do three things: 1. Mapping 936 to GBK instead of GB2312 according to Windows Control Panel->Regional and Language options, which is as same as RI do. 2. Fix one bug in GBK encoding 3. Fix one bug in GB2312 encoding, both of them should minus bbRemaining by one after putting one byte into the buffer. I have ran the nio, nio_char and luni test, no regression.
        Hide
        Regis Xu added a comment -

        regarding 2&3, did they cause this test failure?

        Show
        Regis Xu added a comment - regarding 2&3, did they cause this test failure?
        Hide
        Ray Chen added a comment -

        Hi Regis,

        Let me explain more,
        At first, harmony uses GB2312 on my machine which caused the test error.

        Then after change the encoding mapping, uses GBK, also found the error.

        So I investigated it and found that GBK and GB2312 both have bugs.

        Shall I update the patch and treat them as different defect?


        Regards,

        Ray Chen

        Show
        Ray Chen added a comment - Hi Regis, Let me explain more, At first, harmony uses GB2312 on my machine which caused the test error. Then after change the encoding mapping, uses GBK, also found the error. So I investigated it and found that GBK and GB2312 both have bugs. Shall I update the patch and treat them as different defect? – Regards, Ray Chen
        Hide
        Ray Chen added a comment -

        Hi Regis,
        I think 1 and 2 are related to this issue, so shall I modify the patch
        and open another JIRA to track 3?


        Regards,

        Ray Chen

        Show
        Ray Chen added a comment - Hi Regis, I think 1 and 2 are related to this issue, so shall I modify the patch and open another JIRA to track 3? – Regards, Ray Chen
        Hide
        Regis Xu added a comment -

        Ray, Thanks for your explanation.

        The patch was applied at r893377, please verify.

        Show
        Regis Xu added a comment - Ray, Thanks for your explanation. The patch was applied at r893377, please verify.
        Hide
        Ray Chen added a comment -

        Patch verified. Thanks Regis.

        I wonder if this fix should be merged to java6 branch?

        Actually, this defect was found when I ran the java6 unit tests.

        Show
        Ray Chen added a comment - Patch verified. Thanks Regis. I wonder if this fix should be merged to java6 branch? Actually, this defect was found when I ran the java6 unit tests.
        Hide
        Hudson added a comment -

        Integrated in Harmony-1.5-head-linux-x86_64 #586 (See http://hudson.zones.apache.org/hudson/job/Harmony-1.5-head-linux-x86_64/586/)
        Apply patch for : [classlib][luni]OutputStreamWriterTest got java.nio.BufferOverflowException

        Show
        Hudson added a comment - Integrated in Harmony-1.5-head-linux-x86_64 #586 (See http://hudson.zones.apache.org/hudson/job/Harmony-1.5-head-linux-x86_64/586/ ) Apply patch for : [classlib] [luni] OutputStreamWriterTest got java.nio.BufferOverflowException
        Hide
        Regis Xu added a comment -

        It would be taken into java6 in the next merge I think.

        Show
        Regis Xu added a comment - It would be taken into java6 in the next merge I think.

          People

          • Assignee:
            Regis Xu
            Reporter:
            Ray Chen
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development