src/java.base/share/classes/java/security/SecureClassLoader.java

Print this page

        

@@ -60,12 +60,10 @@
      * permissions.
      */
     private final Map<CodeSourceKey, ProtectionDomain> pdcache
             = new ConcurrentHashMap<>(11);
 
-    private static final Debug debug = Debug.getInstance("scl");
-
     static {
         ClassLoader.registerAsParallelCapable();
     }
 
     /**

@@ -201,10 +199,17 @@
         check();
         return new Permissions(); // ProtectionDomain defers the binding
     }
 
     /*
+     * holder class for the static field "debug" to delay its initialization
+     */
+    private static class DebugHolder {
+        private static final Debug debug = Debug.getInstance("scl");
+    }
+
+    /*
      * Returned cached ProtectionDomain for the specified CodeSource.
      */
     private ProtectionDomain getProtectionDomain(CodeSource cs) {
         if (cs == null) {
             return null;

@@ -220,13 +225,13 @@
             public ProtectionDomain apply(CodeSourceKey key /* not used */) {
                 PermissionCollection perms
                         = SecureClassLoader.this.getPermissions(cs);
                 ProtectionDomain pd = new ProtectionDomain(
                         cs, perms, SecureClassLoader.this, null);
-                if (debug != null) {
-                    debug.println(" getPermissions " + pd);
-                    debug.println("");
+                if (DebugHolder.debug != null) {
+                    DebugHolder.debug.println(" getPermissions " + pd);
+                    DebugHolder.debug.println("");
                 }
                 return pd;
             }
         });
     }