# HG changeset patch # User dfuchs # Date 1381140562 -7200 # Node ID 37f8c8b6ef7af5d865f5986dbd5d009add045884 # Parent d66c8815bebc6cb7d80abbeb5d8da2955e3df8f9 8024867: Enhance logging start up Reviewed-by: mchung, hawtin diff -r d66c8815bebc -r 37f8c8b6ef7a jdk/src/share/classes/java/util/logging/LogManager.java --- a/jdk/src/share/classes/java/util/logging/LogManager.java Mon Oct 07 11:32:48 2013 +0100 +++ b/jdk/src/share/classes/java/util/logging/LogManager.java Mon Oct 07 12:09:22 2013 +0200 @@ -241,6 +241,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()); @@ -250,6 +255,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; + } + /** * Lazy initialization: if this instance of manager is the global * manager then this method will read the initial configuration and