5029431: (bf) Add absolute bulk put and get methods

Alan Bateman Alan.Bateman at oracle.com
Tue Feb 12 08:49:38 UTC 2019


On 11/02/2019 22:30, Brian Burkhalter wrote:
>
> The presence of the absolute index into the buffer complicates the 
> situation. In the absolute get() to an array, for example, 
> get(index,$type$[],offset,length) throwing a BufferUnderflowException 
> would make sense for
>
> 0 <= index < limit() && index + length > limit(),
>
> but if index < 0 or index > limit() an IOOBE appears more logical. 
> Likewise for put(index,$type$[],offset,length), a 
> BufferOverflowException would work for
>
> 0 <= index < limit() && index + length > limit,
>
> but IOOBE again seems more apropos for index < 0 or index > limit(). 
> For any given method where an IOOBE could be thrown for different 
> indexes being out of bounds, then a better disambiguation message as 
> Roger suggested would be helpful. If an IOOBE can be thrown by only 
> one particular index being out of range, then the default 
> checkFromIndexSize() message might be enough. For example, for the code
>
>       byte[] ba = new byte[42];
>         bb.put(-1, ba, 0, 42);
>
> the exception
>
> java.lang.IndexOutOfBoundsException: Range [-1, -1 + 42) out of bounds 
> for length 42
>
> is thrown which looks to be sufficient if we know a priori which index 
> is involved.
>
> For the method put(index,$Type$Buffer,offset,length) the 
> BufferUnderflowException would be for ‘src’ not having enough elements 
> to copy to ‘this’ and the BufferOverflowException for ‘this’ not 
> having enough space before limit() to contain the copied elements. 
> Again, either ‘index’ or ‘offset’ being out of range would be better 
> handled by an IOOBE.
>
> Note that using Buffer*flowException would require an update to the 
> specifications of these exceptions as now they are described as being 
> specific to relative operations.
>
I think you are on the right track with this thinking. That is, throw 
IOOBE when index is negative or >= limit, throw the 
Buffer*flowExceptions if the transfer would result in buffer 
overflow/underflow. I think that will fix the inconsistency with the 
current proposal and also helps with the troubleshooting a bit. Yes, it 
does mean a small adjustment to the wording in the exceptions.

-Alan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/nio-dev/attachments/20190212/b9a8ae6a/attachment.html>


More information about the nio-dev mailing list