# HG changeset patch # User dfuchs # Date 1381140562 -7200 # Node ID 3de6d912bc22f8dcbecf843284e0e8da7ff72955 # Parent 97c4591b09c54e650f0befb5f106700404c5f927 8024867: Enhance logging start up Reviewed-by: mchung, hawtin diff -r 97c4591b09c5 -r 3de6d912bc22 src/share/classes/java/util/logging/LogManager.java --- a/src/share/classes/java/util/logging/LogManager.java Thu Sep 19 20:56:20 2013 +0400 +++ b/src/share/classes/java/util/logging/LogManager.java Mon Oct 07 12:09:22 2013 +0200 @@ -248,6 +248,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()); @@ -257,6 +262,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. */