--- 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();