JDK-8263826 : (bf) MappedByteBuffer.force() should use the capacity as its upper bound
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.nio
  • Priority: P3
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 17
  • Submitted: 2021-03-18
  • Updated: 2021-03-18
  • Resolved: 2021-03-18
Related Reports
CSR :  
Description
Summary
-------

Modify the `MappedByteBuffer` `force()` methods to use as upper bound the capacity instead of the limit.

Problem
-------

Prior to JDK 15, the capacity was used as the upper bound in the `MappedByteBuffer` `force()` methods. Via a sequence of changes described in the associated issue, this upper bound was inadvertently changed to the limit.

Solution
--------

In the `force()` methods of `MappedByteBuffer` change the upper bound to be the capacity.

Specification
-------------

The only part of the specification which is affected are the descriptions of the parameters of `MappedByteBuffer.force(int,int)`:

    @@ -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


Comments
Moving to Approved.
18-03-2021