WW-4587 Adds logic to cache missing bundles

Conflicts:
        core/src/main/java/com/opensymphony/xwork2/util/LocalizedTextUtil.java


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/6fb870d3
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/6fb870d3
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/6fb870d3

Branch: refs/heads/master
Commit: 6fb870d389d9b3c869ee7b2c36d947e944fba3a6
Parents: 5b25645
Author: Lukasz Lenart <lukaszlen...@apache.org>
Authored: Tue Jan 26 10:59:47 2016 +0100
Committer: Lukasz Lenart <lukaszlen...@apache.org>
Committed: Tue Jan 26 11:08:28 2016 +0100

----------------------------------------------------------------------
 .../xwork2/util/LocalizedTextUtil.java          | 26 +++++++++++++-------
 1 file changed, 17 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/6fb870d3/core/src/main/java/com/opensymphony/xwork2/util/LocalizedTextUtil.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/com/opensymphony/xwork2/util/LocalizedTextUtil.java 
b/core/src/main/java/com/opensymphony/xwork2/util/LocalizedTextUtil.java
index fa5a178..7082736 100644
--- a/core/src/main/java/com/opensymphony/xwork2/util/LocalizedTextUtil.java
+++ b/core/src/main/java/com/opensymphony/xwork2/util/LocalizedTextUtil.java
@@ -98,6 +98,7 @@ public class LocalizedTextUtil {
     private static final ConcurrentMap<String, ResourceBundle> bundlesMap = 
new ConcurrentHashMap<>();
     private static final ConcurrentMap<MessageFormatKey, MessageFormat> 
messageFormats = new ConcurrentHashMap<>();
     private static final ConcurrentMap<Integer, ClassLoader> 
delegatedClassLoaderMap = new ConcurrentHashMap<>();
+    private static final Set<String> missingBundles = 
Collections.synchronizedSet(new HashSet<String>());
 
     private static final String RELOADED = 
"com.opensymphony.xwork2.util.LocalizedTextUtil.reloaded";
     private static final String XWORK_MESSAGES_BUNDLE = 
"com/opensymphony/xwork2/xwork-messages";
@@ -261,30 +262,37 @@ public class LocalizedTextUtil {
      * @return the bundle, <tt>null</tt> if not found.
      */
     public static ResourceBundle findResourceBundle(String aBundleName, Locale 
locale) {
-
-        ResourceBundle bundle = null;
-
         ClassLoader classLoader = getCurrentThreadContextClassLoader();
         String key = createMissesKey(String.valueOf(classLoader.hashCode()), 
aBundleName, locale);
+
+        if (missingBundles.contains(key)) {
+            return null;
+        }
+
+        ResourceBundle bundle = null;
         try {
-            if (!bundlesMap.containsKey(key)) {
+            if (bundlesMap.containsKey(key)) {
+                bundle = bundlesMap.get(key);
+            } else {
                 bundle = ResourceBundle.getBundle(aBundleName, locale, 
classLoader);
                 bundlesMap.putIfAbsent(key, bundle);
-            } else {
-                bundle = bundlesMap.get(key);
             }
         } catch (MissingResourceException ex) {
             if (delegatedClassLoaderMap.containsKey(classLoader.hashCode())) {
                 try {
-                    if (!bundlesMap.containsKey(key)) {
+                    if (bundlesMap.containsKey(key)) {
+                        bundle = bundlesMap.get(key);
+                    } else {
                         bundle = ResourceBundle.getBundle(aBundleName, locale, 
delegatedClassLoaderMap.get(classLoader.hashCode()));
                         bundlesMap.putIfAbsent(key, bundle);
-                    } else {
-                        bundle = bundlesMap.get(key);
                     }
                 } catch (MissingResourceException e) {
                     LOG.debug("Missing resource bundle [{}]!", aBundleName, e);
+                    missingBundles.add(key);
                 }
+            } else {
+                LOG.debug("Missing resource bundle [{}]!", aBundleName);
+                missingBundles.add(key);
             }
         }
         return bundle;

Reply via email to