WW-4587 Adds logic to cache missing bundles

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

Branch: refs/heads/support-2-3
Commit: 15c79e139824143872387a877e2631e8f5d873b8
Parents: dd36946
Author: Lukasz Lenart <[email protected]>
Authored: Tue Jan 26 10:59:47 2016 +0100
Committer: Lukasz Lenart <[email protected]>
Committed: Tue Jan 26 10:59:47 2016 +0100

----------------------------------------------------------------------
 .../xwork2/util/LocalizedTextUtil.java          | 30 ++++++++++++--------
 1 file changed, 18 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/15c79e13/xwork-core/src/main/java/com/opensymphony/xwork2/util/LocalizedTextUtil.java
----------------------------------------------------------------------
diff --git 
a/xwork-core/src/main/java/com/opensymphony/xwork2/util/LocalizedTextUtil.java 
b/xwork-core/src/main/java/com/opensymphony/xwork2/util/LocalizedTextUtil.java
index 1e51ded..13a864d 100644
--- 
a/xwork-core/src/main/java/com/opensymphony/xwork2/util/LocalizedTextUtil.java
+++ 
b/xwork-core/src/main/java/com/opensymphony/xwork2/util/LocalizedTextUtil.java
@@ -96,6 +96,7 @@ public class LocalizedTextUtil {
     private static boolean devMode;
 
     private static final ConcurrentMap<String, ResourceBundle> bundlesMap = 
new ConcurrentHashMap<String, ResourceBundle>();
+    private static final Set<String> missingBundles = 
Collections.synchronizedSet(new HashSet<String>());
     private static final ConcurrentMap<MessageFormatKey, MessageFormat> 
messageFormats = new ConcurrentHashMap<MessageFormatKey, MessageFormat>();
     private static final ConcurrentMap<Integer, ClassLoader> 
delegatedClassLoaderMap = new ConcurrentHashMap<Integer, ClassLoader>();
 
@@ -259,32 +260,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) {
-                    if (LOG.isDebugEnabled()) {
-                        LOG.debug("Missing resource bundle [#0]!", 
aBundleName);
-                    }
+                    LOG.debug("Missing resource bundle [#0]!", aBundleName);
+                    missingBundles.add(key);
                 }
+            } else {
+                LOG.debug("Missing resource bundle [#0]!", aBundleName);
+                missingBundles.add(key);
             }
         }
         return bundle;

Reply via email to