This is an automated email from the ASF dual-hosted git repository.

cshannon pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/accumulo-classloaders.git


The following commit(s) were added to refs/heads/main by this push:
     new b4ecd67  Remove usage of deprecated AccessController (#19)
b4ecd67 is described below

commit b4ecd6794df2043127952e68b5420e9acc85cd3e
Author: Christopher L. Shannon <[email protected]>
AuthorDate: Fri Mar 3 10:01:39 2023 -0500

    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.
---
 .../ReloadingVFSContextClassLoaderFactory.java     | 58 ++++++++++-----------
 .../classloader/vfs/VfsClassLoaderTest.java        | 21 +++-----
 .../ReloadingVFSContextClassLoaderFactoryTest.java | 60 ++++++++++------------
 3 files changed, 61 insertions(+), 78 deletions(-)

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.io.IOException;
 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 org.slf4j.LoggerFactory;
 
 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 @@ public class ReloadingVFSContextClassLoaderFactory 
implements ContextClassLoader
     });
   }
 
+  @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.assertNotNull;
 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 @@ public class VfsClassLoaderTest extends AccumuloDFSBase {
     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 static org.junit.Assert.fail;
 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 @@ public class ReloadingVFSContextClassLoaderFactoryTest {
       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;
     }
   }
 

Reply via email to