harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Geir Magnusson Jr <g...@pobox.com>
Subject Re: [DRLVM][JNI]GetByteArrayRegion differs from RI (was Re: Exceptions found while running servlet...)
Date Mon, 14 Aug 2006 19:37:06 GMT

Gregory Shimansky wrote:
> On Monday 14 August 2006 20:13 Geir Magnusson Jr wrote:
>> Ivan Volosyuk wrote:
>>> It looks like that it is possible to get zero bytes even at the very
>>> end of array. IMHO the order of boundary checks makes sense here.
>> This is an interesting problem. The JNI spec is clear that we should
>> throw an exception when one of the indexes isn't valid, and start ==
>> size is arguably not valid, as Gregory points out.
>> So I think the JNI impl is right for now (but I want to test w/ the JNI
>> impl in RI....)
> I've written a test [1] myself and cannot say I completely understand the 
> result. With length = 0 RI 1.5 allows calling to Get<type>ArrayRegion with 
> start equal to array length but throws AIOOBE if start is greater than array 
> length.

That makes sense to me, only because I am thinking of j.i.OutputStream's
write([], int, int) method, which does state that it's ok if start + len
 == arraylen...

I'm sure if we thought about it, we'd figure out that it lends itself
nicely to some common loop idiom. I suspect it will be some end case
when some read returns an empty buffer, so

  write(buf, 0, 0)

works without a check, or some situation where there's some post
decrement leading you to

  write(buf, length, len)

where the len was calculated from (buf.length - length) or something.

Now, that isn't what the JNI spec says, but it seems like the JNI spec
was written in a hurry... :)

> I am unsure if we want to allow this compatibility and a reason to allow it. 
> When length is 0 the application still gets nothing except for clear 
> exception status. There is no value in allowing this call except for allowing 
> software which has a bug in it to work. On the other hand allowing start == 
> length to pass violates the spec IMHO.
> I think it is better if software which uses this undocumented feature was 
> fixed instead of introducing this workaround, so if others agree I think 
> HARMONY-1156 could be closed.

Well, I don't feel strongly either way, but am uncomfortable with the
inconsistency.  The JNI docs seem pretty sparse, and clearly some
thought went into allowing :

  write( buff, buff.length, 0)


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

View raw message