JDK-8263742 : (bf) MappedByteBuffer.force() should use the capacity as its upper bound
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 15,16
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2021-03-17
  • Updated: 2021-03-25
  • Resolved: 2021-03-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 17
17 b15Fixed
Related Reports
CSR :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
The fix for JDK-8221696 added MappedByteBuffer(int index, int length) to allow specifying a range to write back to storage. The no-arg MappedByteBuffer at this time and before wrote back the entire buffer content, i.e., the half-open range [0,capacity()). The new force(int,int) checked its parameters using Objects.checkFromIndexSize(index, length, limit()), i.e., with the limit instead of the capacity as upper bound. In JDK-8243491 the no-arg force() was changed as

@@ -293,8 +227,7 @@ public abstract class MappedByteBuffer
             return force(0, limit());
         }
         if ((address != 0) && (capacity() != 0)) {
-            long offset = mappingOffset();
-            force0(fd, mappingAddress(offset), mappingLength(offset));
+            return force(0, capacity());
         }
         return this;
     }

to call the new force(int,int). This inadvertently changed the upper bound of the no-arg force() from capacity() to limit() thereby provoking JDK-8246729. The upper bound of force() should be the capacity.
Comments
Changeset: fa0f1614 Author: Brian Burkhalter <bpb@openjdk.org> Date: 2021-03-18 21:12:33 +0000 URL: https://git.openjdk.java.net/jdk/commit/fa0f1614
18-03-2021

noreg-other: Change is covered by existing tests.
17-03-2021