7199551: (bf) CharBuffer.append(CharSequence) throws BufferOverflowException for read-only buffer
Chris Hegarty
chris.hegarty at oracle.com
Thu Sep 20 07:39:53 PDT 2012
On 20/09/2012 15:06, Alan Bateman wrote:
> On 20/09/2012 11:42, Chris Hegarty wrote:
>>
>> My comment here is that I think put(CharBuffer src) will throw
>> BufferOverflowException even if the buffer is read only. Where as the
>> other put methods do the opposite, right?
> You are right, and my apologies I didn't quite grok what you were
> getting at first. Your observation has promoted me to look at
> put(CharBuffer) where I see that the lack of an explicit check for
> read-only means that it will read one element from the source buffer
> before it throws ReadOnlyBufferException.
>
> As this needs an explicit check then it brings up the question as to the
> ordering of the checks. For this double error case (attempting to do a
> bulk put into a read-only buffer that just have enough space remaining)
> then I think the read-only check is better to do first. I realize this
> is a small behavior change (I can relate to people that might need to
> catch ReadOnlyBufferException; on the other hand BufferOverflowException
> probably means a bug somewhere).
>
> The updated webrev is here:
>
> http://cr.openjdk.java.net/~alanb/7199551/webrev/
This change looks much better to me.
-Chris.
>
> This is for jdk8 only of course.
>
> -Alan
>
>
More information about the nio-dev
mailing list