RFR: 8266320: (bf) ReadOnlyBufferException in heap buffer put(String, int, int) should not be conditional [v2]

Alan Bateman alanb at openjdk.java.net
Sat May 1 16:39:51 UTC 2021


On Sat, 1 May 2021 13:18:31 GMT, Philippe Marschall <github.com+471021+marschall at openjdk.org> wrote:

>> src/java.base/share/classes/java/nio/Heap-X-Buffer.java.template line 289:
>> 
>>> 287: #else[rw]
>>> 288:         throw new ReadOnlyBufferException();
>>> 289: #end[rw]
>> 
>> I assume this isn't technically a bug in that it's unspecified which exception is thrown when the buffer is read-only and an index is out of range. The change is okay of course. It would be useful to run the tests without the addition to Basic-X.java.template as I would expect this case to be covered by an existing test already.
>
>>  would expect this case to be covered by an existing test already.
> 
> Upon closer inspection this line seems to cover it already. It also establishes the existing behavior to be throwing `ReadOnlyBufferException` and not `BufferOverflowException`. Should I undo the added test in `Basic-X.java.template` and not add the bug id to `Basic.java`?
> 
> https://github.com/openjdk/jdk/blob/5c083e8560ce9cc78615e3149a558206724cff53/test/jdk/java/nio/Buffer/Basic-X.java.template#L1003

Yes, I expected it was tested already so I think you can drop the change to Basic-X.java.template from the patch.

That leaves the change to throw ReadOnlyBufferException unconditionally. As I said, if someone were to invoke this method on a read-only CharBuffer and with an out of range start or end index then ReadOnlyBufferException or IndexOutOfBoundsException are applicable. Existing behavior is to throw IOOBE. It's possible, but probably unlikely, that the behavior change will be observed by someone. A Release Note could be helpful.

-------------

PR: https://git.openjdk.java.net/jdk/pull/3809


More information about the nio-dev mailing list