1.1 --- a/src/share/jaf_classes/javax/activation/FileTypeMap.java Fri Dec 13 17:20:01 2013 -0800 1.2 +++ b/src/share/jaf_classes/javax/activation/FileTypeMap.java Sun Dec 15 23:35:45 2013 +0100 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -26,6 +26,8 @@ 1.11 package javax.activation; 1.12 1.13 import java.io.File; 1.14 +import java.util.Map; 1.15 +import java.util.WeakHashMap; 1.16 1.17 /** 1.18 * The FileTypeMap is an abstract class that provides a data typing 1.19 @@ -48,6 +50,8 @@ 1.20 public abstract class FileTypeMap { 1.21 1.22 private static FileTypeMap defaultMap = null; 1.23 + private static Map<ClassLoader,FileTypeMap> map = 1.24 + new WeakHashMap<ClassLoader,FileTypeMap>(); 1.25 1.26 /** 1.27 * The default constructor. 1.28 @@ -78,11 +82,11 @@ 1.29 * Sets the default FileTypeMap for the system. This instance 1.30 * will be returned to callers of getDefaultFileTypeMap. 1.31 * 1.32 - * @param map The FileTypeMap. 1.33 + * @param fileTypeMap The FileTypeMap. 1.34 * @exception SecurityException if the caller doesn't have permission 1.35 * to change the default 1.36 */ 1.37 - public static void setDefaultFileTypeMap(FileTypeMap map) { 1.38 + public static synchronized void setDefaultFileTypeMap(FileTypeMap fileTypeMap) { 1.39 SecurityManager security = System.getSecurityManager(); 1.40 if (security != null) { 1.41 try { 1.42 @@ -90,14 +94,17 @@ 1.43 security.checkSetFactory(); 1.44 } catch (SecurityException ex) { 1.45 // otherwise, we also allow it if this code and the 1.46 - // factory come from the same class loader (e.g., 1.47 + // factory come from the same (non-system) class loader (e.g., 1.48 // the JAF classes were loaded with the applet classes). 1.49 - if (FileTypeMap.class.getClassLoader() != 1.50 - map.getClass().getClassLoader()) 1.51 + if (FileTypeMap.class.getClassLoader() == null || 1.52 + FileTypeMap.class.getClassLoader() != 1.53 + fileTypeMap.getClass().getClassLoader()) 1.54 throw ex; 1.55 } 1.56 } 1.57 - defaultMap = map; 1.58 + // remove any per-thread-context-class-loader FileTypeMap 1.59 + map.remove(SecuritySupport.getContextClassLoader()); 1.60 + defaultMap = fileTypeMap; 1.61 } 1.62 1.63 /** 1.64 @@ -109,10 +116,17 @@ 1.65 * @return The default FileTypeMap 1.66 * @see javax.activation.FileTypeMap#setDefaultFileTypeMap 1.67 */ 1.68 - public static FileTypeMap getDefaultFileTypeMap() { 1.69 - // XXX - probably should be synchronized 1.70 - if (defaultMap == null) 1.71 - defaultMap = new MimetypesFileTypeMap(); 1.72 - return defaultMap; 1.73 + public static synchronized FileTypeMap getDefaultFileTypeMap() { 1.74 + if (defaultMap != null) 1.75 + return defaultMap; 1.76 + 1.77 + // fetch per-thread-context-class-loader default 1.78 + ClassLoader tccl = SecuritySupport.getContextClassLoader(); 1.79 + FileTypeMap def = map.get(tccl); 1.80 + if (def == null) { 1.81 + def = new MimetypesFileTypeMap(); 1.82 + map.put(tccl, def); 1.83 + } 1.84 + return def; 1.85 } 1.86 }