RFR: 6539707: (fc) MappedByteBuffer.force() method throws an IOException in a very simple test [v2]

Alan Bateman alanb at openjdk.java.net
Wed Feb 24 08:30:42 UTC 2021


On Wed, 24 Feb 2021 00:30:05 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> This change proposes to increase the number of retries of `FlushViewOfFile` in the Windows native implementation of `MappedByteBuffer.force()`, and to catch any exception thrown by the native `force()` and rethrow an `UncheckedIOException` with cause set to the intercepted exception. A sentence is added to the specification of `MappedByteBuffer.force()` regarding unspecified errors. The test from the issue description is revised to fail if `force()` throws an exception which is not an `UncheckedIOException`, or if it is an `UncheckedIOException` whose message indicates it was thrown by the Windows native implementation of `force()`.
>
> Brian Burkhalter has updated the pull request incrementally with two additional commits since the last revision:
> 
>  - 6539707: Fix whitespace error
>  - 6539707: Spec force() method of MappedByteBuffer and MappedMemorySegments to throw UncheckedIOException

src/java.base/share/classes/java/nio/MappedByteBuffer.java line 230:

> 228:      * @return  This buffer
> 229:      */
> 230:     public final MappedByteBuffer force() {

The 2-arg force method will need to be updated too.
Given that the methods are specified to write the buffer content back to the underlying storage device then I think it should be okay to say "If an I/O occurs writing the ...".

src/java.base/share/classes/java/nio/MappedMemoryUtils.java line 100:

> 98:             long offset = mappingOffset(address, index);
> 99:             try {
> 100:                 force0(fd, mappingAddress(address, offset, index),

Are you going to change force0 to declare that it throws IOException? I assumed you'd need to do that to get this code to compile.

-------------

PR: https://git.openjdk.java.net/jdk/pull/2636


More information about the nio-dev mailing list