Remove usage of deprecated AccessController (#19)
The SecurityManager and related classes, including AccessController,
have been deprecated as of JDK 17 and are planned for removal. This
commit removes the usage of the APIs.
diff --git a/modules/vfs-class-loader/src/main/java/org/apache/accumulo/classloader/vfs/context/ReloadingVFSContextClassLoaderFactory.java b/modules/vfs-class-loader/src/main/java/org/apache/accumulo/classloader/vfs/context/ReloadingVFSContextClassLoaderFactory.java
index f5bebcc..7a546e9 100644
--- a/modules/vfs-class-loader/src/main/java/org/apache/accumulo/classloader/vfs/context/ReloadingVFSContextClassLoaderFactory.java
+++ b/modules/vfs-class-loader/src/main/java/org/apache/accumulo/classloader/vfs/context/ReloadingVFSContextClassLoaderFactory.java
@@ -23,8 +23,6 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -37,6 +35,8 @@
import com.google.gson.Gson;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
/**
* A ClassLoaderFactory implementation that uses a ReloadingVFSClassLoader per defined context.
* Configuration of this class is done with a JSON file whose location is defined by the system
@@ -282,39 +282,35 @@
});
}
+ @SuppressFBWarnings(value = "DP_CREATE_CLASSLOADER_INSIDE_DO_PRIVILEGED",
+ justification = "Security Manager is deprecated for removal as of JDK 17")
protected AccumuloVFSClassLoader create(Context c) {
LOG.debug("Creating ReloadingVFSClassLoader for context: {})", c.getName());
- return AccessController.doPrivileged(new PrivilegedAction<AccumuloVFSClassLoader>() {
+ return new AccumuloVFSClassLoader(
+ ReloadingVFSContextClassLoaderFactory.class.getClassLoader()) {
@Override
- public AccumuloVFSClassLoader run() {
- return new AccumuloVFSClassLoader(
- ReloadingVFSContextClassLoaderFactory.class.getClassLoader()) {
- @Override
- protected String getClassPath() {
- return c.getConfig().getClassPath();
- }
-
- @Override
- protected boolean isPostDelegationModel() {
- LOG.debug("isPostDelegationModel called, returning {}",
- c.getConfig().getPostDelegate());
- return c.getConfig().getPostDelegate();
- }
-
- @Override
- protected long getMonitorInterval() {
- return c.getConfig().getMonitorIntervalMs();
- }
-
- @Override
- protected boolean isVMInitialized() {
- // The classloader is not being set using
- // `java.system.class.loader`, so the VM is initialized.
- return true;
- }
- };
+ protected String getClassPath() {
+ return c.getConfig().getClassPath();
}
- });
+
+ @Override
+ protected boolean isPostDelegationModel() {
+ LOG.debug("isPostDelegationModel called, returning {}", c.getConfig().getPostDelegate());
+ return c.getConfig().getPostDelegate();
+ }
+
+ @Override
+ protected long getMonitorInterval() {
+ return c.getConfig().getMonitorIntervalMs();
+ }
+
+ @Override
+ protected boolean isVMInitialized() {
+ // The classloader is not being set using
+ // `java.system.class.loader`, so the VM is initialized.
+ return true;
+ }
+ };
}
@Override
diff --git a/modules/vfs-class-loader/src/test/java/org/apache/accumulo/classloader/vfs/VfsClassLoaderTest.java b/modules/vfs-class-loader/src/test/java/org/apache/accumulo/classloader/vfs/VfsClassLoaderTest.java
index 3ee15b6..e5a5cd1 100644
--- a/modules/vfs-class-loader/src/test/java/org/apache/accumulo/classloader/vfs/VfsClassLoaderTest.java
+++ b/modules/vfs-class-loader/src/test/java/org/apache/accumulo/classloader/vfs/VfsClassLoaderTest.java
@@ -23,8 +23,6 @@
import static org.junit.Assert.assertTrue;
import java.net.URL;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
import java.util.Arrays;
import org.apache.commons.vfs2.FileChangeEvent;
@@ -82,17 +80,14 @@
FileObject[] dirContents = testDir.getChildren();
LOG.info("Test directory contents according to VFS: {}", Arrays.toString(dirContents));
- VFSClassLoader cl = AccessController.doPrivileged(new PrivilegedAction<VFSClassLoader>() {
- @Override
- public VFSClassLoader run() {
- // Point the VFSClassLoader to all of the objects in TEST_DIR
- try {
- return new VFSClassLoader(dirContents, vfs);
- } catch (FileSystemException e) {
- throw new RuntimeException("Error creating VFSClassLoader", e);
- }
- }
- });
+ final VFSClassLoader cl;
+
+ // Point the VFSClassLoader to all of the objects in TEST_DIR
+ try {
+ cl = new VFSClassLoader(dirContents, vfs);
+ } catch (FileSystemException e) {
+ throw new RuntimeException("Error creating VFSClassLoader", e);
+ }
LOG.info("VFSClassLoader has the following files: {}", Arrays.toString(cl.getFileObjects()));
LOG.info("Looking for HelloWorld.class");
diff --git a/modules/vfs-class-loader/src/test/java/org/apache/accumulo/classloader/vfs/context/ReloadingVFSContextClassLoaderFactoryTest.java b/modules/vfs-class-loader/src/test/java/org/apache/accumulo/classloader/vfs/context/ReloadingVFSContextClassLoaderFactoryTest.java
index 034cf8b..4846b3c 100644
--- a/modules/vfs-class-loader/src/test/java/org/apache/accumulo/classloader/vfs/context/ReloadingVFSContextClassLoaderFactoryTest.java
+++ b/modules/vfs-class-loader/src/test/java/org/apache/accumulo/classloader/vfs/context/ReloadingVFSContextClassLoaderFactoryTest.java
@@ -28,8 +28,6 @@
import java.io.BufferedWriter;
import java.io.File;
import java.nio.file.Files;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.List;
@@ -64,43 +62,37 @@
this.dir = dir;
}
+ @SuppressFBWarnings(value = "DP_CREATE_CLASSLOADER_INSIDE_DO_PRIVILEGED",
+ justification = "Security Manager is deprecated for removal as of JDK 17")
@Override
protected AccumuloVFSClassLoader create(Context c) {
- AccumuloVFSClassLoader acl =
- AccessController.doPrivileged(new PrivilegedAction<AccumuloVFSClassLoader>() {
+ final AccumuloVFSClassLoader cl =
+ new AccumuloVFSClassLoader(ReloadingVFSContextClassLoaderFactory.class.getClassLoader()) {
@Override
- public AccumuloVFSClassLoader run() {
- AccumuloVFSClassLoader cl = new AccumuloVFSClassLoader(
- ReloadingVFSContextClassLoaderFactory.class.getClassLoader()) {
- @Override
- protected String getClassPath() {
- return dir;
- }
-
- @Override
- protected boolean isPostDelegationModel() {
- LOG.debug("isPostDelegationModel called, returning {}",
- c.getConfig().getPostDelegate());
- return c.getConfig().getPostDelegate();
- }
-
- @Override
- protected long getMonitorInterval() {
- return 500l;
- }
-
- @Override
- protected boolean isVMInitialized() {
- return true;
- }
- };
- cl.setVMInitializedForTests();
- cl.setMaxRetries(2);
- return cl;
+ protected String getClassPath() {
+ return dir;
}
- });
- return acl;
+ @Override
+ protected boolean isPostDelegationModel() {
+ LOG.debug("isPostDelegationModel called, returning {}",
+ c.getConfig().getPostDelegate());
+ return c.getConfig().getPostDelegate();
+ }
+
+ @Override
+ protected long getMonitorInterval() {
+ return 500l;
+ }
+
+ @Override
+ protected boolean isVMInitialized() {
+ return true;
+ }
+ };
+ cl.setVMInitializedForTests();
+ cl.setMaxRetries(2);
+ return cl;
}
}