diff --git a/client/src/main/java-mvnd/org/mvndaemon/mvnd/client/DefaultClient.java b/client/src/main/java-mvnd/org/mvndaemon/mvnd/client/DefaultClient.java
index 75d18aa0..fe3fbeb0 100644
--- a/client/src/main/java-mvnd/org/mvndaemon/mvnd/client/DefaultClient.java
+++ b/client/src/main/java-mvnd/org/mvndaemon/mvnd/client/DefaultClient.java
@@ -230,6 +230,7 @@ public class DefaultClient implements Client {
"--add-opens java.base/java.io=ALL-UNNAMED "
+ "--add-opens java.base/java.lang=ALL-UNNAMED "
+ "--add-opens java.base/java.util=ALL-UNNAMED "
+ + "--add-opens java.base/jdk.internal.misc=ALL-UNNAMED "
+ "--add-opens java.base/sun.net.www.protocol.jar=ALL-UNNAMED "
+ "--add-opens java.base/sun.nio.fs=ALL-UNNAMED",
true);
diff --git a/common/pom.xml b/common/pom.xml
index 122cb692..4b1122a8 100644
--- a/common/pom.xml
+++ b/common/pom.xml
@@ -92,6 +92,13 @@
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+ --add-opens java.base/jdk.internal.misc=ALL-UNNAMED
+
+
diff --git a/common/src/main/java/org/mvndaemon/mvnd/common/BufferHelper.java b/common/src/main/java/org/mvndaemon/mvnd/common/BufferHelper.java
index ef5acac0..e9d7aecd 100644
--- a/common/src/main/java/org/mvndaemon/mvnd/common/BufferHelper.java
+++ b/common/src/main/java/org/mvndaemon/mvnd/common/BufferHelper.java
@@ -21,248 +21,62 @@ package org.mvndaemon.mvnd.common;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
import java.util.function.Consumer;
/**
- * Original code from
- * https://github.com/classgraph/classgraph/blob/latest/src/main/java/nonapi/io/github/classgraph/utils/FileUtils.java#L543
+ * Utility class to clean up direct {@link ByteBuffer} instances by explicitly invoking their cleaner.
*/
public class BufferHelper {
- private static boolean PRE_JAVA_9 =
- System.getProperty("java.specification.version", "9").startsWith("1.");
-
- /** The DirectByteBuffer.cleaner() method. */
- private static Method directByteBufferCleanerMethod;
-
- /** The Cleaner.clean() method. */
- private static Method cleanerCleanMethod;
-
- // /** The jdk.incubator.foreign.MemorySegment class (JDK14+). */
- // private static Class> memorySegmentClass;
- //
- // /** The jdk.incubator.foreign.MemorySegment.ofByteBuffer method (JDK14+). */
- // private static Method memorySegmentOfByteBufferMethod;
- //
- // /** The jdk.incubator.foreign.MemorySegment.ofByteBuffer method (JDK14+). */
- // private static Method memorySegmentCloseMethod;
-
- /** The attachment() method. */
- private static Method attachmentMethod;
-
- /** The Unsafe object. */
- private static Object theUnsafe;
-
- /**
- * Get the clean() method, attachment() method, and theUnsafe field, called inside doPrivileged.
- */
- static void lookupCleanMethodPrivileged() {
- if (PRE_JAVA_9) {
- try {
- // See:
- // https://stackoverflow.com/a/19447758/3950982
- cleanerCleanMethod = Class.forName("sun.misc.Cleaner").getDeclaredMethod("clean");
- cleanerCleanMethod.setAccessible(true);
- final Class> directByteBufferClass = Class.forName("sun.nio.ch.DirectBuffer");
- directByteBufferCleanerMethod = directByteBufferClass.getDeclaredMethod("cleaner");
- attachmentMethod = directByteBufferClass.getMethod("attachment");
- attachmentMethod.setAccessible(true);
- } catch (final SecurityException e) {
- throw new RuntimeException(
- "You need to grant classgraph RuntimePermission(\"accessClassInPackage.sun.misc\") "
- + "and ReflectPermission(\"suppressAccessChecks\")",
- e);
- } catch (final ReflectiveOperationException | LinkageError e) {
- // Ignore
- }
- } else {
- // boolean jdkSuccess = false;
- // // TODO: This feature is in incubation now -- enable after it leaves incubation.
- // // To enable this feature, need to:
- // // -- add whatever the "jdk.incubator.foreign" module name is replaced with to
- // // in pom.xml, as an optional dependency
- // // -- add the same module name to module-info.java as a "requires static" optional dependency
- // // -- build two versions of module.java: the existing one, for --release=9, and a new version,
- // // for --release=15 (or whatever the final release version ends up being when the feature is
- // // moved out of incubation).
- // try {
- // // JDK 14+ Invoke MemorySegment.ofByteBuffer(myByteBuffer).close()
- // // https://stackoverflow.com/a/26777380/3950982
- // memorySegmentClass = Class.forName("jdk.incubator.foreign.MemorySegment");
- // memorySegmentCloseMethod = AutoCloseable.class.getDeclaredMethod("close");
- // memorySegmentOfByteBufferMethod = memorySegmentClass.getMethod("ofByteBuffer",
- // ByteBuffer.class);
- // jdk14Success = true;
- // } catch (ClassNotFoundException | NoSuchMethodException | SecurityException e1) {
- // // Fall through
- // }
- // if (!jdk14Success) { // In JDK9+, calling sun.misc.Cleaner.clean() gives a reflection warning on stderr,
- // so we need to call Unsafe.theUnsafe.invokeCleaner(byteBuffer) instead, which makes
- // the same call, but does not print the reflection warning.
- try {
- Class> unsafeClass;
- try {
- unsafeClass = Class.forName("sun.misc.Unsafe");
- } catch (final ReflectiveOperationException | LinkageError e) {
- throw new RuntimeException("Could not get class sun.misc.Unsafe", e);
- }
- final Field theUnsafeField = unsafeClass.getDeclaredField("theUnsafe");
- theUnsafeField.setAccessible(true);
- theUnsafe = theUnsafeField.get(null);
- cleanerCleanMethod = unsafeClass.getMethod("invokeCleaner", ByteBuffer.class);
- cleanerCleanMethod.setAccessible(true);
- } catch (final SecurityException e) {
- throw new RuntimeException(
- "You need to grant classgraph RuntimePermission(\"accessClassInPackage.sun.misc\") "
- + "and ReflectPermission(\"suppressAccessChecks\")",
- e);
- } catch (final ReflectiveOperationException | LinkageError ex) {
- // Ignore
- }
- // }
- }
- }
+ private static final Object unsafe;
+ private static final java.lang.reflect.Method invokeCleanerMethod;
static {
- AccessController.doPrivileged(new PrivilegedAction