--- a/jaxws/src/share/jaf_classes/javax/activation/CommandMap.java Wed Jul 05 19:36:17 2017 +0200
+++ b/jaxws/src/share/jaf_classes/javax/activation/CommandMap.java Sun Dec 15 23:35:45 2013 +0100
@@ -25,6 +25,9 @@
package javax.activation;
+import java.util.Map;
+import java.util.WeakHashMap;
+
/**
* The CommandMap class provides an interface to a registry of
@@ -38,6 +41,8 @@
*/
public abstract class CommandMap {
private static CommandMap defaultCommandMap = null;
+ private static Map<ClassLoader,CommandMap> map =
+ new WeakHashMap<ClassLoader,CommandMap>();
/**
* Get the default CommandMap.
@@ -56,11 +61,18 @@
*
* @return the CommandMap
*/
- public static CommandMap getDefaultCommandMap() {
- if (defaultCommandMap == null)
- defaultCommandMap = new MailcapCommandMap();
+ public static synchronized CommandMap getDefaultCommandMap() {
+ if (defaultCommandMap != null)
+ return defaultCommandMap;
- return defaultCommandMap;
+ // fetch per-thread-context-class-loader default
+ ClassLoader tccl = SecuritySupport.getContextClassLoader();
+ CommandMap def = map.get(tccl);
+ if (def == null) {
+ def = new MailcapCommandMap();
+ map.put(tccl, def);
+ }
+ return def;
}
/**
@@ -71,7 +83,7 @@
* @exception SecurityException if the caller doesn't have permission
* to change the default
*/
- public static void setDefaultCommandMap(CommandMap commandMap) {
+ public static synchronized void setDefaultCommandMap(CommandMap commandMap) {
SecurityManager security = System.getSecurityManager();
if (security != null) {
try {
@@ -79,13 +91,16 @@
security.checkSetFactory();
} catch (SecurityException ex) {
// otherwise, we also allow it if this code and the
- // factory come from the same class loader (e.g.,
+ // factory come from the same (non-system) class loader (e.g.,
// the JAF classes were loaded with the applet classes).
- if (CommandMap.class.getClassLoader() !=
+ if (CommandMap.class.getClassLoader() == null ||
+ CommandMap.class.getClassLoader() !=
commandMap.getClass().getClassLoader())
throw ex;
}
}
+ // remove any per-thread-context-class-loader CommandMap
+ map.remove(SecuritySupport.getContextClassLoader());
defaultCommandMap = commandMap;
}