Fix bug where copy
with over-sized length threw a wrong exception
This commit is contained in:
parent
b1b2c983f8
commit
050db15e07
@ -189,12 +189,7 @@ class NioBuffer extends ResourceSupport<Buffer, NioBuffer> implements Buffer, Re
|
||||
|
||||
@Override
|
||||
public Buffer copy(int offset, int length) {
|
||||
if (length < 0) {
|
||||
throw new IllegalArgumentException("Length cannot be negative: " + length + '.');
|
||||
}
|
||||
if (!isAccessible()) {
|
||||
throw new IllegalStateException("This buffer is closed: " + this + '.');
|
||||
}
|
||||
checkGet(offset, length);
|
||||
int allocSize = Math.max(length, 1); // Allocators don't support allocating zero-sized buffers.
|
||||
AllocatorControl.UntetheredMemory memory = control.allocateUntethered(this, allocSize);
|
||||
ByteBuffer base = memory.memory();
|
||||
|
@ -166,11 +166,7 @@ class UnsafeBuffer extends ResourceSupport<Buffer, UnsafeBuffer> implements Buff
|
||||
|
||||
@Override
|
||||
public Buffer copy(int offset, int length) {
|
||||
if (length < 0) {
|
||||
throw new IllegalArgumentException("Length cannot be negative: " + length + '.');
|
||||
}
|
||||
checkGet(offset, length);
|
||||
|
||||
int allocSize = Math.max(length, 1); // Allocators don't support allocating zero-sized buffers.
|
||||
AllocatorControl.UntetheredMemory memory = control.allocateUntethered(this, allocSize);
|
||||
UnsafeMemory unsafeMemory = memory.memory();
|
||||
|
@ -299,12 +299,6 @@ class MemSegBuffer extends ResourceSupport<Buffer, MemSegBuffer> implements Buff
|
||||
@Override
|
||||
public Buffer copy(int offset, int length) {
|
||||
checkGet(offset, length);
|
||||
if (length < 0) {
|
||||
throw new IllegalArgumentException("Length cannot be negative: " + length + '.');
|
||||
}
|
||||
if (!isAccessible()) {
|
||||
throw new IllegalStateException("This buffer is closed: " + this + '.');
|
||||
}
|
||||
|
||||
if (length == 0) {
|
||||
// Special case zero-length segments, since allocators don't support allocating empty buffers.
|
||||
|
Loading…
Reference in New Issue
Block a user