5071718: (bf) Add ByteBuffer.slice(int offset, int length)

Roger Riggs Roger.Riggs at oracle.com
Mon Feb 25 14:48:11 UTC 2019

Hi Brian,

Is it intentional to prevent being able to create a zero length slice
at index == limit?

Buffer: 618: and 628 with regards to the IOOBE

index must be non-negative and less than  limit()

I think that forces application code to do some unnecessary workarounds
at a boundary condition.

The relative slice() method does not restrict the case where position() 
== limit().

Thanks, Roger

On 02/23/2019 01:15 PM, Alan Bateman wrote:
> On 22/02/2019 23:34, Brian Burkhalter wrote:
>> Please review the proposed fix [1] for issue [2] the CSR of which is 
>> [3]. The fix changes the existing package scope slice(int,int) method 
>> to be slice(index,length) instead of slice(position,limit) and 
>> modifies alignedSlice() accordingly. Overrides are added as needed 
>> for heap, direct, view, and StringChar buffers.
>> I suggest perhaps addressing the specification content first so that 
>> the CSR can move forward.
> I think this looks okay. The usefulness will be mostly ByteBuffer but 
> I think okay to have it defined by each of the buffer classes. The 
> "Additional operations" section in Buffer's javadoc will need a small 
> update to mention the 2-arg slice.
> -Alan.

More information about the nio-dev mailing list