Skip to content

Commit

Permalink
8263742: (bf) MappedByteBuffer.force() should use the capacity as its…
Browse files Browse the repository at this point in the history
… upper bound

Reviewed-by: adinn, alanb
  • Loading branch information
Brian Burkhalter committed Mar 18, 2021
1 parent c82a673 commit fa0f161
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/java.base/share/classes/java/nio/MappedByteBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ public final MappedByteBuffer force() {
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;
}
Expand Down Expand Up @@ -267,11 +267,11 @@ public final MappedByteBuffer force() {
* @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
Expand All @@ -289,10 +289,10 @@ public final MappedByteBuffer force(int index, int length) {
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;
Expand Down

1 comment on commit fa0f161

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.