diff -r b549c5ea34ab -r 2fcd3ddb57a6 src/share/jaf_classes/javax/activation/FileTypeMap.java --- a/src/share/jaf_classes/javax/activation/FileTypeMap.java Fri Dec 13 17:20:01 2013 -0800 +++ b/src/share/jaf_classes/javax/activation/FileTypeMap.java Sun Dec 15 23:35:45 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,6 +26,8 @@ package javax.activation; import java.io.File; +import java.util.Map; +import java.util.WeakHashMap; /** * The FileTypeMap is an abstract class that provides a data typing @@ -48,6 +50,8 @@ public abstract class FileTypeMap { private static FileTypeMap defaultMap = null; + private static Map map = + new WeakHashMap(); /** * The default constructor. @@ -78,11 +82,11 @@ * Sets the default FileTypeMap for the system. This instance * will be returned to callers of getDefaultFileTypeMap. * - * @param map The FileTypeMap. + * @param fileTypeMap The FileTypeMap. * @exception SecurityException if the caller doesn't have permission * to change the default */ - public static void setDefaultFileTypeMap(FileTypeMap map) { + public static synchronized void setDefaultFileTypeMap(FileTypeMap fileTypeMap) { SecurityManager security = System.getSecurityManager(); if (security != null) { try { @@ -90,14 +94,17 @@ 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 (FileTypeMap.class.getClassLoader() != - map.getClass().getClassLoader()) + if (FileTypeMap.class.getClassLoader() == null || + FileTypeMap.class.getClassLoader() != + fileTypeMap.getClass().getClassLoader()) throw ex; } } - defaultMap = map; + // remove any per-thread-context-class-loader FileTypeMap + map.remove(SecuritySupport.getContextClassLoader()); + defaultMap = fileTypeMap; } /** @@ -109,10 +116,17 @@ * @return The default FileTypeMap * @see javax.activation.FileTypeMap#setDefaultFileTypeMap */ - public static FileTypeMap getDefaultFileTypeMap() { - // XXX - probably should be synchronized - if (defaultMap == null) - defaultMap = new MimetypesFileTypeMap(); - return defaultMap; + public static synchronized FileTypeMap getDefaultFileTypeMap() { + if (defaultMap != null) + return defaultMap; + + // fetch per-thread-context-class-loader default + ClassLoader tccl = SecuritySupport.getContextClassLoader(); + FileTypeMap def = map.get(tccl); + if (def == null) { + def = new MimetypesFileTypeMap(); + map.put(tccl, def); + } + return def; } }