8306623: (bf) CharBuffer::allocate throws unexpected exception type with some CharSequences

Reviewed-by: alanb, lancea
This commit is contained in:
Brian Burkhalter 2023-04-25 20:18:19 +00:00
parent d819debaa5
commit e3ccaa6541
4 changed files with 74 additions and 5 deletions

View file

@ -2045,8 +2045,17 @@ public abstract sealed class $Type$Buffer
*/
public $Type$Buffer append(CharSequence csq, int start, int end) {
if (csq instanceof CharBuffer cb) {
int pos = position();
//
// the append method throws BufferOverflowException when
// there is insufficient space in the buffer
//
int length = end - start;
int pos = position();
int lim = limit();
int rem = (pos <= lim) ? lim - pos : 0;
if (length > rem)
throw new BufferOverflowException();
put(pos, cb, start, length);
position(pos + length);
return this;