changeset 16497:028f221e28a7

8171140: Re-examine ResourceBundle::clearCache method Reviewed-by: mchung, dfuchs
author naoto
date Wed, 18 Jan 2017 08:03:04 -0800
parents 5b75946223fb
children e15c8b97a107
files src/java.base/share/classes/java/util/ResourceBundle.java
diffstat 1 files changed, 7 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/util/ResourceBundle.java	Wed Jan 18 13:56:50 2017 +0000
+++ b/src/java.base/share/classes/java/util/ResourceBundle.java	Wed Jan 18 08:03:04 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2017, 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
@@ -2134,7 +2134,7 @@
 
     /**
      * Removes all resource bundles from the cache that have been loaded
-     * by the caller's module using the caller's class loader.
+     * by the caller's module.
      *
      * @since 1.6
      * @see ResourceBundle.Control#getTimeToLive(String,Locale)
@@ -2142,50 +2142,26 @@
     @CallerSensitive
     public static final void clearCache() {
         Class<?> caller = Reflection.getCallerClass();
-        clearCacheImpl(caller.getModule(), caller.getClassLoader());
+        cacheList.keySet().removeIf(
+            key -> key.getCallerModule() == caller.getModule()
+        );
     }
 
     /**
      * Removes all resource bundles from the cache that have been loaded
-     * by the caller's module using the given class loader.
+     * by the given class loader.
      *
      * @param loader the class loader
      * @exception NullPointerException if <code>loader</code> is null
      * @since 1.6
      * @see ResourceBundle.Control#getTimeToLive(String,Locale)
      */
-    @CallerSensitive
     public static final void clearCache(ClassLoader loader) {
         Objects.requireNonNull(loader);
-        Class<?> caller = Reflection.getCallerClass();
-        clearCacheImpl(caller.getModule(), loader);
-    }
-
-    /**
-     * Removes all resource bundles from the cache that have been loaded by the
-     * given {@code module}.
-     *
-     * @param module the module
-     * @throws NullPointerException
-     *         if {@code module} is {@code null}
-     * @throws SecurityException
-     *         if the caller doesn't have the permission to
-     *         {@linkplain Module#getClassLoader() get the class loader}
-     *         of the given {@code module}
-     * @since 9
-     * @see ResourceBundle.Control#getTimeToLive(String,Locale)
-     */
-    public static final void clearCache(Module module) {
-        Objects.requireNonNull(module);
-        clearCacheImpl(module, module.getClassLoader());
-    }
-
-    private static void clearCacheImpl(Module callerModule, ClassLoader loader) {
         cacheList.keySet().removeIf(
             key -> {
                 Module m;
-                return key.getCallerModule() == callerModule &&
-                       (m = key.getModule()) != null &&
+                return (m = key.getModule()) != null &&
                        getLoader(m) == loader;
             }
         );