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

Print this page

        

@@ -137,12 +137,10 @@
     /*
      * An object used as a key when the ProtectionDomain is stored in a Map.
      */
     final Key key = new Key();
 
-    private static final Debug debug = Debug.getInstance("domain");
-
     /**
      * Creates a new ProtectionDomain with the given CodeSource and
      * Permissions. If the permissions object is not null, then
      *  {@code setReadOnly())} will be called on the passed in
      * Permissions object. The only permissions granted to this domain

@@ -336,10 +334,17 @@
             " "+classloader+"\n"+
             " "+pals+"\n"+
             " "+pc+"\n";
     }
 
+    /*
+     * holder class for the static field "debug" to delay its initialization
+     */
+    private static class DebugHolder {
+        private static final Debug debug = Debug.getInstance("domain");
+    }
+
     /**
      * Return true (merge policy permissions) in the following cases:
      *
      * . SecurityManager is null
      *

@@ -357,11 +362,11 @@
         SecurityManager sm = System.getSecurityManager();
 
         if (sm == null) {
             return true;
         } else {
-            if (debug != null) {
+            if (DebugHolder.debug != null) {
                 if (sm.getClass().getClassLoader() == null &&
                     Policy.getPolicyNoCheck().getClass().getClassLoader()
                                                                 == null) {
                     return true;
                 }