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

Alan Bateman alanb at openjdk.java.net
Sun Feb 21 16:54:39 UTC 2021


On Fri, 19 Feb 2021 00:34:24 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()`.

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

> 291:             try {
> 292:                 SCOPED_MEMORY_ACCESS.force(scope(), fd, address, isSync, index, length);
> 293:             } catch (Exception unspecifiedException) {

The force method should be changed to declare that it throws IOException and that will avoid the need to catch "unexpectedException" here.

Also I think we to need to decide if the force methods should be specified to throw UncheckedIOException rather than an "unspecified exception". The API changes will need to be coordinated with Project Panama and the MappedMemorySegments.force spec.

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

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


More information about the nio-dev mailing list