--- old/src/share/classes/java/util/logging/Handler.java 2013-12-18 17:42:55.553392550 +0100
+++ new/src/share/classes/java/util/logging/Handler.java 2013-12-18 17:42:55.476394010 +0100
@@ -27,6 +27,9 @@
package java.util.logging;
import java.io.UnsupportedEncodingException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
/**
* A Handler object takes log messages from a Logger and
* exports them. It might for example, write them to a console
@@ -62,10 +65,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 +301,48 @@
}
// 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();
+ }
+
+ // Package-private support for configuring various properties
+ // with specified/configured/default values
+
+ Level getDefaultLevel() { return Level.INFO; }
+
+ Formatter getDefaultFormatter() { return new SimpleFormatter(); }
+
+ void configure(Formatter specifiedFormatter) {
+ LogManager manager = LogManager.getLogManager();
+ String cname = getClass().getName();
+
+ final Level level = manager.getLevelProperty(cname + ".level", getDefaultLevel());
+ final Filter filter = manager.getFilterProperty(cname + ".filter", null);
+ final Formatter formatter = specifiedFormatter == null
+ ? manager.getFormatterProperty(cname + ".formatter", getDefaultFormatter())
+ : specifiedFormatter;
+ final String encoding = manager.getStringProperty(cname + ".encoding", null);
+
+ AccessController.doPrivileged(new PrivilegedAction() {
+ @Override
+ public Void run() {
+ setLevel(level);
+ setFilter(filter);
+ setFormatter(formatter);
+ try {
+ setEncoding(encoding);
+ } catch (Exception ex) {
+ try {
+ setEncoding(null);
+ } catch (Exception ex2) {
+ // doing a setEncoding with null should always work.
+ // assert false;
+ }
+ }
+ return null;
+ }
+ }, null, LogManager.controlPermission);
}
}