You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Tony Wu (JIRA)" <ji...@apache.org> on 2006/09/20 05:24:23 UTC

[jira] Commented: (HARMONY-1175) [classlib][io] BufferedWriter.write() exception behavior differ from RI

    [ http://issues.apache.org/jira/browse/HARMONY-1175?page=comments#action_12436096 ] 
            
Tony Wu commented on HARMONY-1175:
----------------------------------

It is no longer an issue in latest code (r448046)

> [classlib][io] BufferedWriter.write() exception behavior differ from RI
> -----------------------------------------------------------------------
>
>                 Key: HARMONY-1175
>                 URL: http://issues.apache.org/jira/browse/HARMONY-1175
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Denis Kishenko
>         Attachments: 1175-BufferedWriter.patch, 1175-BufferedWriterTest.patch
>
>
> 1. Harmony implementation of BufferedWriter.write(String, int, int) throws an exception if len is negative while spec says (and RI follows it)
> public void write(String s, int off, int len) throws IOExceptionWrite a portion of a String. 
> If the value of the len parameter is negative then no characters are written. This is contrary to the specification of this method in the superclass, which requires that an IndexOutOfBoundsException be thrown. 
> 2. Harmony implementation of BufferedWriter.write(char[], int, int)  throws ArrayIndexOutOfBoundsException while RI throws IndexOutOfBoundsException.
> =========================== Test ===============================
> import java.io.*;
> public class bug9588 {
>     static void test(String name, Object buf, int offset, int count) {
>         try {
>             System.err.println(name);
>             ByteArrayOutputStream baos = new ByteArrayOutputStream(200);
>             OutputStreamWriter osw = new OutputStreamWriter(baos);
>             BufferedWriter bw = new BufferedWriter((Writer)osw);
>             if (buf instanceof String) {
>                 bw.write((String)buf, offset, count);
>             } else {
>                 bw.write((char[])buf, offset, count);
>             }
>             bw.flush();
>             System.err.println("Number of written chars: " +(baos.toByteArray()).length);
>         } catch (Exception e) {
>             e.printStackTrace();
>         }  
>     }
>     public static void main (String [] args) throws Exception  {
>         String str = "abcde";
>         char[] ch = new char[] {'a', 'b', 'c', 'd', 'e'}; 
>         test("1", str, 1, -1);
>         test("2", str, -1, 1);
>         test("3", str, -1, -1);
>         test("4", str, 7, 1);
>         test("5", str, 3, 4);        
>         test("6", ch, 1, -1);
>         test("7", ch, -1, 1);
>         test("8", ch, -1, -1);
>         test("9", ch, 7, 1);
>         test("10", ch, 3, 4);        
>     }
> }
> =================== Output ==========================
> RI
> 1
> Number of written chars: 0
> 2
> java.lang.StringIndexOutOfBoundsException: String index out of range: -1
>     at java.lang.String.getChars(II[CI)V(Unknown Source)
>     at java.io.BufferedWriter.write(BufferedWriter.java:208)
>     at bug9588.test(bug9588.java:12)
>     at bug9588.main(bug9588.java:27)
> 3
> Number of written chars: 0
> 4
> java.lang.StringIndexOutOfBoundsException: String index out of range: 8
>     at java.lang.String.getChars(II[CI)V(Unknown Source)
>     at java.io.BufferedWriter.write(BufferedWriter.java:208)
>     at bug9588.test(bug9588.java:12)
>     at bug9588.main(bug9588.java:29)
> 5
> java.lang.StringIndexOutOfBoundsException: String index out of range: 7
>     at java.lang.String.getChars(II[CI)V(Unknown Source)
>     at java.io.BufferedWriter.write(BufferedWriter.java:208)
>     at bug9588.test(bug9588.java:12)
>     at bug9588.main(bug9588.java:30)
> 6
> java.lang.IndexOutOfBoundsException
>     at java.io.BufferedWriter.write(BufferedWriter.java:160)
>     at bug9588.test(bug9588.java:14)
>     at bug9588.main(bug9588.java:31)
> 7
> java.lang.IndexOutOfBoundsException
>     at java.io.BufferedWriter.write(BufferedWriter.java:160)
>     at bug9588.test(bug9588.java:14)
>     at bug9588.main(bug9588.java:32)
> 8
> java.lang.IndexOutOfBoundsException
>     at java.io.BufferedWriter.write(BufferedWriter.java:160)
>     at bug9588.test(bug9588.java:14)
>     at bug9588.main(bug9588.java:33)
> 9
> java.lang.IndexOutOfBoundsException
>     at java.io.BufferedWriter.write(BufferedWriter.java:160)
>     at bug9588.test(bug9588.java:14)
>     at bug9588.main(bug9588.java:34)
> 10
> java.lang.IndexOutOfBoundsException
>     at java.io.BufferedWriter.write(BufferedWriter.java:160)
>     at bug9588.test(bug9588.java:14)
>     at bug9588.main(bug9588.java:35)
> Harmony
> 1
> java.lang.StringIndexOutOfBoundsException
>     at java.io.BufferedWriter.write(BufferedWriter.java:291)
>     at bug9588.test(bug9588.java:12)
>     at bug9588.main(bug9588.java:26)
> 2
> java.lang.StringIndexOutOfBoundsException
>     at java.io.BufferedWriter.write(BufferedWriter.java:291)
>     at bug9588.test(bug9588.java:12)
>     at bug9588.main(bug9588.java:27)
> 3
> java.lang.StringIndexOutOfBoundsException
>     at java.io.BufferedWriter.write(BufferedWriter.java:291)
>     at bug9588.test(bug9588.java:12)
>     at bug9588.main(bug9588.java:28)
> 4
> java.lang.StringIndexOutOfBoundsException
>     at java.io.BufferedWriter.write(BufferedWriter.java:291)
>     at bug9588.test(bug9588.java:12)
>     at bug9588.main(bug9588.java:29)
> 5
> java.lang.StringIndexOutOfBoundsException
>     at java.io.BufferedWriter.write(BufferedWriter.java:291)
>     at bug9588.test(bug9588.java:12)
>     at bug9588.main(bug9588.java:30)
> 6
> java.lang.ArrayIndexOutOfBoundsException
>     at java.io.BufferedWriter.write(BufferedWriter.java:198)
>     at bug9588.test(bug9588.java:14)
>     at bug9588.main(bug9588.java:31)
> 7
> java.lang.ArrayIndexOutOfBoundsException
>     at java.io.BufferedWriter.write(BufferedWriter.java:198)
>     at bug9588.test(bug9588.java:14)
>     at bug9588.main(bug9588.java:32)
> 8
> java.lang.ArrayIndexOutOfBoundsException
>     at java.io.BufferedWriter.write(BufferedWriter.java:198)
>     at bug9588.test(bug9588.java:14)
>     at bug9588.main(bug9588.java:33)
> 9
> java.lang.ArrayIndexOutOfBoundsException
>     at java.io.BufferedWriter.write(BufferedWriter.java:198)
>     at bug9588.test(bug9588.java:14)
>     at bug9588.main(bug9588.java:34)
> 10
> java.lang.ArrayIndexOutOfBoundsException
>     at java.io.BufferedWriter.write(BufferedWriter.java:198)
>     at bug9588.test(bug9588.java:14)
>     at bug9588.main(bug9588.java:35)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira