8263742: (bf) MappedByteBuffer.force() should use the capacity as its upper bound

Reviewed-by: adinn, alanb
This commit is contained in:
Brian Burkhalter 2021-03-18 21:12:33 +00:00
parent c82a673cf6
commit fa0f1614ff

@ -232,9 +232,9 @@ public abstract class MappedByteBuffer
if (fd == null) {
return this;
}
int limit = limit();
if (isSync || ((address != 0) && (limit != 0))) {
return force(0, limit);
int capacity = capacity();
if (isSync || ((address != 0) && (capacity != 0))) {
return force(0, capacity);
}
return this;
}
@ -267,11 +267,11 @@ public abstract class MappedByteBuffer
* @param index
* The index of the first byte in the buffer region that is
* to be written back to storage; must be non-negative
* and less than limit()
* and less than {@code capacity()}
*
* @param length
* The length of the region in bytes; must be non-negative
* and no larger than limit() - index
* and no larger than {@code capacity() - index}
*
* @throws IndexOutOfBoundsException
* if the preconditions on the index and length do not
@ -289,10 +289,10 @@ public abstract class MappedByteBuffer
if (fd == null) {
return this;
}
int limit = limit();
if ((address != 0) && (limit != 0)) {
int capacity = capacity();
if ((address != 0) && (capacity != 0)) {
// check inputs
Objects.checkFromIndexSize(index, length, limit);
Objects.checkFromIndexSize(index, length, capacity);
SCOPED_MEMORY_ACCESS.force(scope(), fd, address, isSync, index, length);
}
return this;