From bd6090b2a8fecf42de78b4ff85935fd05088c861 Mon Sep 17 00:00:00 2001 From: Anton Skubyev Date: Tue, 4 Jul 2023 16:31:22 +0300 Subject: [PATCH] Support new FileChannelImpl.map0() contract from JDK 19 (#75) * Support new FileChannelImpl.map0 contract * Support new FileChannelImpl.map0 contract --------- Co-authored-by: 1ou --- src/one/nio/mem/MappedFile.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/one/nio/mem/MappedFile.java b/src/one/nio/mem/MappedFile.java index 1c3328b..3c9d22b 100755 --- a/src/one/nio/mem/MappedFile.java +++ b/src/one/nio/mem/MappedFile.java @@ -170,6 +170,12 @@ public static long map(RandomAccessFile f, int mode, long start, long size) thro if (map0 != null) { return (long) map0.invoke(f.getChannel(), mode, start, size, false); } + // Since 19 JDK has an extra 'file descriptor' argument + map0 = JavaInternals.getMethod( + cls, "map0", FileDescriptor.class, int.class, long.class, long.class, boolean.class); + if (map0 != null) { + return (long) map0.invoke(f.getFD(), f.getChannel(), mode, start, size, false); + } throw new IllegalStateException("map0 method not found"); } catch (InvocationTargetException e) { Throwable target = e.getTargetException();