changeset 6865:15c242aefefd

8024867: Enhance logging start up Reviewed-by: mchung, hawtin
author dfuchs
date Mon, 07 Oct 2013 12:09:22 +0200
parents dc04e86b0dac
children 35644fe4a796
files src/share/classes/java/util/logging/LogManager.java
diffstat 1 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/logging/LogManager.java	Fri Oct 04 19:39:59 2013 +0400
+++ b/src/share/classes/java/util/logging/LogManager.java	Mon Oct 07 12:09:22 2013 +0200
@@ -257,6 +257,11 @@
      * retrieved by calling Logmanager.getLogManager.
      */
     protected LogManager() {
+        this(checkSubclassPermissions());
+    }
+
+    private LogManager(Void checked) {
+
         // Add a shutdown hook to close the global handlers.
         try {
             Runtime.getRuntime().addShutdownHook(new Cleaner());
@@ -266,6 +271,19 @@
         }
     }
 
+    private static Void checkSubclassPermissions() {
+        final SecurityManager sm = System.getSecurityManager();
+        if (sm != null) {
+            // These permission will be checked in the LogManager constructor,
+            // in order to register the Cleaner() thread as a shutdown hook.
+            // Check them here to avoid the penalty of constructing the object
+            // etc...
+            sm.checkPermission(new RuntimePermission("shutdownHooks"));
+            sm.checkPermission(new RuntimePermission("setContextClassLoader"));
+        }
+        return null;
+    }
+
     /**
      * Return the global LogManager object.
      */