--- old/src/share/classes/java/util/logging/ConsoleHandler.java 2013-12-14 11:47:28.778020919 +0100 +++ new/src/share/classes/java/util/logging/ConsoleHandler.java 2013-12-14 11:47:28.658022996 +0100 @@ -26,6 +26,9 @@ package java.util.logging; +import java.security.AccessController; +import java.security.PrivilegedAction; + /** * This Handler publishes log records to System.err. * By default the SimpleFormatter is used to generate brief summaries. @@ -66,25 +69,30 @@ * @since 1.4 */ public class ConsoleHandler extends StreamHandler { - // Private method to configure a ConsoleHandler from LogManager + // Private PrivilegedAction to configure a ConsoleHandler from LogManager // properties and/or default values as specified in the class // javadoc. - private void configure() { - LogManager manager = LogManager.getLogManager(); - String cname = getClass().getName(); - - setLevel(manager.getLevelProperty(cname +".level", Level.INFO)); - setFilter(manager.getFilterProperty(cname +".filter", null)); - setFormatter(manager.getFormatterProperty(cname +".formatter", new SimpleFormatter())); - try { - setEncoding(manager.getStringProperty(cname +".encoding", null)); - } catch (Exception ex) { + private class ConfigureAction implements PrivilegedAction { + @Override + public Void run() { + LogManager manager = LogManager.getLogManager(); + String cname = ConsoleHandler.this.getClass().getName(); + + setLevel(manager.getLevelProperty(cname +".level", Level.INFO)); + setFilter(manager.getFilterProperty(cname +".filter", null)); + setFormatter(manager.getFormatterProperty(cname +".formatter", new SimpleFormatter())); try { - setEncoding(null); - } catch (Exception ex2) { - // doing a setEncoding with null should always work. - // assert false; + setEncoding(manager.getStringProperty(cname +".encoding", null)); + } catch (Exception ex) { + try { + setEncoding(null); + } catch (Exception ex2) { + // doing a setEncoding with null should always work. + // assert false; + } } + setOutputStream(System.err); + return null; } } @@ -96,10 +104,7 @@ * */ public ConsoleHandler() { - sealed = false; - configure(); - setOutputStream(System.err); - sealed = true; + AccessController.doPrivileged(new ConfigureAction(), null, LogManager.controlPermission); } /** --- old/src/share/classes/java/util/logging/Handler.java 2013-12-14 11:47:29.088015554 +0100 +++ new/src/share/classes/java/util/logging/Handler.java 2013-12-14 11:47:28.971017579 +0100 @@ -27,6 +27,7 @@ package java.util.logging; import java.io.UnsupportedEncodingException; + /** * A Handler object takes log messages from a Logger and * exports them. It might for example, write them to a console @@ -62,10 +63,6 @@ private volatile ErrorManager errorManager = new ErrorManager(); private volatile String encoding; - // Package private support for security checking. When sealed - // is true, we access check updates to the class. - boolean sealed = true; - /** * Default constructor. The resulting Handler has a log * level of Level.ALL, no Formatter, and no @@ -302,12 +299,9 @@ } // Package-private support method for security checks. - // If "sealed" is true, we check that the caller has - // appropriate security privileges to update Handler - // state and if not throw a SecurityException. + // We check that the caller has appropriate security privileges + // to update Handler state and if not throw a SecurityException. void checkPermission() throws SecurityException { - if (sealed) { - manager.checkPermission(); - } + manager.checkPermission(); } } --- old/src/share/classes/java/util/logging/LogManager.java 2013-12-14 11:47:29.415009895 +0100 +++ new/src/share/classes/java/util/logging/LogManager.java 2013-12-14 11:47:29.289012075 +0100 @@ -1557,7 +1557,7 @@ loadLoggerHandlers(rootLogger, null, "handlers"); } - private final Permission controlPermission = new LoggingPermission("control", null); + static final Permission controlPermission = new LoggingPermission("control", null); void checkPermission() { SecurityManager sm = System.getSecurityManager(); --- old/src/share/classes/java/util/logging/MemoryHandler.java 2013-12-14 11:47:29.759003941 +0100 +++ new/src/share/classes/java/util/logging/MemoryHandler.java 2013-12-14 11:47:29.635006087 +0100 @@ -25,6 +25,9 @@ package java.util.logging; +import java.security.AccessController; +import java.security.PrivilegedAction; + /** * Handler that buffers requests in a circular buffer in memory. *

@@ -94,21 +97,25 @@ private LogRecord buffer[]; int start, count; - // Private method to configure a MemoryHandler from LogManager + // Private PrivilegedAction to configure a MemoryHandler from LogManager // properties and/or default values as specified in the class // javadoc. - private void configure() { - LogManager manager = LogManager.getLogManager(); - String cname = getClass().getName(); - - pushLevel = manager.getLevelProperty(cname +".push", Level.SEVERE); - size = manager.getIntProperty(cname + ".size", DEFAULT_SIZE); - if (size <= 0) { - size = DEFAULT_SIZE; + private class ConfigureAction implements PrivilegedAction { + @Override + public Void run() { + LogManager manager = LogManager.getLogManager(); + String cname = MemoryHandler.this.getClass().getName(); + + pushLevel = manager.getLevelProperty(cname +".push", Level.SEVERE); + size = manager.getIntProperty(cname + ".size", DEFAULT_SIZE); + if (size <= 0) { + size = DEFAULT_SIZE; + } + setLevel(manager.getLevelProperty(cname +".level", Level.ALL)); + setFilter(manager.getFilterProperty(cname +".filter", null)); + setFormatter(manager.getFormatterProperty(cname +".formatter", new SimpleFormatter())); + return null; } - setLevel(manager.getLevelProperty(cname +".level", Level.ALL)); - setFilter(manager.getFilterProperty(cname +".filter", null)); - setFormatter(manager.getFormatterProperty(cname +".formatter", new SimpleFormatter())); } /** @@ -116,9 +123,7 @@ * LogManager configuration properties. */ public MemoryHandler() { - sealed = false; - configure(); - sealed = true; + AccessController.doPrivileged(new ConfigureAction(), null, LogManager.controlPermission); LogManager manager = LogManager.getLogManager(); String handlerName = getClass().getName(); @@ -164,9 +169,7 @@ if (size <= 0) { throw new IllegalArgumentException(); } - sealed = false; - configure(); - sealed = true; + AccessController.doPrivileged(new ConfigureAction(), null, LogManager.controlPermission); this.target = target; this.pushLevel = pushLevel; this.size = size; --- old/src/share/classes/java/util/logging/SocketHandler.java 2013-12-14 11:47:30.077998420 +0100 +++ new/src/share/classes/java/util/logging/SocketHandler.java 2013-12-14 11:47:29.955000549 +0100 @@ -28,6 +28,8 @@ import java.io.*; import java.net.*; +import java.security.AccessController; +import java.security.PrivilegedAction; /** * Simple network logging Handler. @@ -83,31 +85,34 @@ private String host; private int port; - // Private method to configure a SocketHandler from LogManager + // Private PrivilegedAction to configure a SocketHandler from LogManager // properties and/or default values as specified in the class // javadoc. - private void configure() { - LogManager manager = LogManager.getLogManager(); - String cname = getClass().getName(); - - setLevel(manager.getLevelProperty(cname +".level", Level.ALL)); - setFilter(manager.getFilterProperty(cname +".filter", null)); - setFormatter(manager.getFormatterProperty(cname +".formatter", new XMLFormatter())); - try { - setEncoding(manager.getStringProperty(cname +".encoding", null)); - } catch (Exception ex) { + private class ConfigureAction implements PrivilegedAction { + @Override + public Void run() { + LogManager manager = LogManager.getLogManager(); + String cname = SocketHandler.this.getClass().getName(); + + setLevel(manager.getLevelProperty(cname +".level", Level.ALL)); + setFilter(manager.getFilterProperty(cname +".filter", null)); + setFormatter(manager.getFormatterProperty(cname +".formatter", new XMLFormatter())); try { - setEncoding(null); - } catch (Exception ex2) { - // doing a setEncoding with null should always work. - // assert false; + setEncoding(manager.getStringProperty(cname +".encoding", null)); + } catch (Exception ex) { + try { + setEncoding(null); + } catch (Exception ex2) { + // doing a setEncoding with null should always work. + // assert false; + } } + port = manager.getIntProperty(cname + ".port", 0); + host = manager.getStringProperty(cname + ".host", null); + return null; } - port = manager.getIntProperty(cname + ".port", 0); - host = manager.getStringProperty(cname + ".host", null); } - /** * Create a SocketHandler, using only LogManager properties * (or their defaults). @@ -118,16 +123,23 @@ */ public SocketHandler() throws IOException { // We are going to use the logging defaults. - sealed = false; - configure(); - try { - connect(); - } catch (IOException ix) { + AccessController.doPrivileged(new ConfigureAction() { + @Override + public Void run() { + super.run(); + try { + connect(); + } catch (IOException ioe) { + throw new UncheckedIOException(ioe); + } + return null; + } + }, null, LogManager.controlPermission); + } catch (UncheckedIOException uioe) { System.err.println("SocketHandler: connect failed to " + host + ":" + port); - throw ix; + throw uioe.getCause(); } - sealed = true; } /** @@ -146,9 +158,7 @@ * host and port. */ public SocketHandler(String host, int port) throws IOException { - sealed = false; - configure(); - sealed = true; + AccessController.doPrivileged(new ConfigureAction(), null, LogManager.controlPermission); this.port = port; this.host = host; connect(); --- old/src/share/classes/java/util/logging/StreamHandler.java 2013-12-14 11:47:30.397992882 +0100 +++ new/src/share/classes/java/util/logging/StreamHandler.java 2013-12-14 11:47:30.272995045 +0100 @@ -27,6 +27,8 @@ package java.util.logging; import java.io.*; +import java.security.AccessController; +import java.security.PrivilegedAction; /** * Stream based logging Handler. @@ -77,25 +79,29 @@ private boolean doneHeader; private volatile Writer writer; - // Private method to configure a StreamHandler from LogManager + // Private PrivilegedAction to configure a StreamHandler from LogManager // properties and/or default values as specified in the class // javadoc. - private void configure() { - LogManager manager = LogManager.getLogManager(); - String cname = getClass().getName(); - - setLevel(manager.getLevelProperty(cname +".level", Level.INFO)); - setFilter(manager.getFilterProperty(cname +".filter", null)); - setFormatter(manager.getFormatterProperty(cname +".formatter", new SimpleFormatter())); - try { - setEncoding(manager.getStringProperty(cname +".encoding", null)); - } catch (Exception ex) { + private class ConfigureAction implements PrivilegedAction { + @Override + public Void run() { + LogManager manager = LogManager.getLogManager(); + String cname = StreamHandler.this.getClass().getName(); + + setLevel(manager.getLevelProperty(cname +".level", Level.INFO)); + setFilter(manager.getFilterProperty(cname +".filter", null)); + setFormatter(manager.getFormatterProperty(cname +".formatter", new SimpleFormatter())); try { - setEncoding(null); - } catch (Exception ex2) { - // doing a setEncoding with null should always work. - // assert false; + setEncoding(manager.getStringProperty(cname +".encoding", null)); + } catch (Exception ex) { + try { + setEncoding(null); + } catch (Exception ex2) { + // doing a setEncoding with null should always work. + // assert false; + } } + return null; } } @@ -103,9 +109,7 @@ * Create a StreamHandler, with no current output stream. */ public StreamHandler() { - sealed = false; - configure(); - sealed = true; + AccessController.doPrivileged(new ConfigureAction(), null, LogManager.controlPermission); } /** @@ -115,12 +119,16 @@ * @param out the target output stream * @param formatter Formatter to be used to format output */ - public StreamHandler(OutputStream out, Formatter formatter) { - sealed = false; - configure(); - setFormatter(formatter); - setOutputStream(out); - sealed = true; + public StreamHandler(final OutputStream out, final Formatter formatter) { + AccessController.doPrivileged(new ConfigureAction() { + @Override + public Void run() { + super.run(); + setFormatter(formatter); + setOutputStream(out); + return null; + } + }, null, LogManager.controlPermission); } /**