From 61e7dbb67ea75faa691f5d5a483c8dd155b75248 Mon Sep 17 00:00:00 2001 From: Daniel Fuchs Date: Mon, 7 Oct 2013 12:09:22 +0200 Subject: [PATCH] 8024867: Enhance logging start up Reviewed-by: mchung, hawtin --- .../classes/java/util/logging/LogManager.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/jdk/src/share/classes/java/util/logging/LogManager.java b/jdk/src/share/classes/java/util/logging/LogManager.java index 8596cbeb8fe..4c8a99f5199 100644 --- a/jdk/src/share/classes/java/util/logging/LogManager.java +++ b/jdk/src/share/classes/java/util/logging/LogManager.java @@ -241,6 +241,11 @@ public class LogManager { * 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()); @@ -250,6 +255,19 @@ public class LogManager { } } + 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; + } + /** * Lazy initialization: if this instance of manager is the global * manager then this method will read the initial configuration and