harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexey Petrenko" <alexey.a.petre...@gmail.com>
Subject Re: [jira] Created: (HARMONY-1175) [classlib][io] BufferedWriter.write() exception behavior differ from RI
Date Mon, 14 Aug 2006 13:21:33 GMT
2006/8/14, Denis Kishenko (JIRA) <jira@apache.org>:
> [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
>
>
> 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.
I think that this is not a problem since
ArrayIndexOutOfBoundsException is a subclass of
IndexOutOfBoundsException...

SY, Alexey

>
> =========================== 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
>
>
>


-- 
Alexey A. Petrenko
Intel Middleware Products Division

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Mime
View raw message