You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by Geir Magnusson Jr <ge...@pobox.com> on 2006/08/14 18:15:53 UTC
[classlib][luni] Problem with java.io.OutputStream
When looking at HARMONY-1156, it became clear that our
java.io.OutputStream isn't right.
I'd like to make the following changes :
Follow the spec so that an IndexOOBE is thrown when :
a) offset is negative or
b) len is negative or
c) off + len > buff.length
So in the case of
write( byte[count], count, 0);
for any value of count >= 0, then none of the conditions are true, and
it should simply [quickly] return.
Now, the spec says that if the array is null, then a NPE should be
thrown, but this doesn't happen in the RI when len = 0.
This seems to be a reasonable thing to do, and therefore I think that we
should match the RI here, and not the spec.
Comments?
geir
---------------------------------------------------------------------
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
Re: [classlib][luni] Problem with java.io.OutputStream
Posted by "Jimmy, Jing Lv" <fi...@gmail.com>.
Geir Magnusson Jr wrote:
> When looking at HARMONY-1156, it became clear that our
> java.io.OutputStream isn't right.
>
> I'd like to make the following changes :
>
> Follow the spec so that an IndexOOBE is thrown when :
>
> a) offset is negative or
> b) len is negative or
> c) off + len > buff.length
>
> So in the case of
>
> write( byte[count], count, 0);
>
> for any value of count >= 0, then none of the conditions are true, and
> it should simply [quickly] return.
>
> Now, the spec says that if the array is null, then a NPE should be
> thrown, but this doesn't happen in the RI when len = 0.
>
> This seems to be a reasonable thing to do, and therefore I think that we
> should match the RI here, and not the spec.
>
> Comments?
>
Hi Geir,
Sorry I don't catch well here. I write a test[1], extends
OutputStream and try passing a null byte and len = 0, RI and Harmony
both throw NPE(windows XP sp2, RI 1.5.06, the lastest Harmony,J9/DRLVM).
And HARMONY-1156 only asks if given "write( byte[count], count, 0);"
the write operation quickly returns. And we see it is better to fix in
JNI, am I right?
In fact, IMHO we are NOT breaking spec in return quickly as spec
does not tell clear what "indexes in the region is not valid"? :)
[1]
public void test_OutputStream () throws IOException {
try {
new MockOutputStream().write(null, 0, 0);
fail("should throw NPE");
} catch (NullPointerException e) {
// expected
}
}
class MockOutputStream extends OutputStream {
public void write(int oneByte) throws IOException {
throw new NotYetImplementedException();
}
}
> geir
>
>
> ---------------------------------------------------------------------
> 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
>
>
--
Best Regards!
Jimmy, Jing Lv
China Software Development Lab, IBM
---------------------------------------------------------------------
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
Re: [classlib][luni] Problem with java.io.OutputStream
Posted by Andrew Zhang <zh...@gmail.com>.
On 8/15/06, Geir Magnusson Jr <ge...@pobox.com> wrote:
>
> When looking at HARMONY-1156, it became clear that our
> java.io.OutputStream isn't right.
>
> I'd like to make the following changes :
>
> Follow the spec so that an IndexOOBE is thrown when :
>
> a) offset is negative or
> b) len is negative or
> c) off + len > buff.length
>
> So in the case of
>
> write( byte[count], count, 0);
>
> for any value of count >= 0, then none of the conditions are true, and
> it should simply [quickly] return.
>
> Now, the spec says that if the array is null, then a NPE should be
> thrown, but this doesn't happen in the RI when len = 0.
Yes. It's a common exception throw sequence of RI.
Vladimir Ivanov has provided a util patch for such exception check, iirc.
For detail, please refer to Harmony-942 (
http://issues.apache.org/jira/browse/HARMONY-942).
Following code snippet is copied from Harmony-942 patch. Does it work for
this problem?
public static void assertArrayIndex(byte[] array, int offset, int length) {
if (offset < 0 || length < 0) {
throw new IndexOutOfBoundsException(Msg.getString("K0006"));
}
if ((long)offset+(long)length > array.length) {
throw new IndexOutOfBoundsException(Msg.getString("K00ae"));
}
}
Of course, If long cast looks not elegant, we can change the code as
following:
"if (offset > array.length-length) ".
This seems to be a reasonable thing to do, and therefore I think that we
> should match the RI here, and not the spec.
>
> Comments?
>
> geir
>
>
> ---------------------------------------------------------------------
> 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
>
>
--
Andrew Zhang
China Software Development Lab, IBM