Commits

Anonymous committed ebb5481

XW-567
- SpringObjectFactory doesn't protect its internal HashMap from concurrent read/write

git-svn-id: http://svn.opensymphony.com/svn/xwork/branches/xwork_1-2/src@1613e221344d-f017-0410-9bd5-d282ab1896d7

Comments (0)

Files changed (1)

java/com/opensymphony/xwork/spring/SpringObjectFactory.java

  * before the xwork.xml file is parsed. In a servlet environment, this could be done using a ServletContextListener.
  *
  * @author Simon Stewart (sms@lateral.net)
+ * @author tmjee
  */
 public class SpringObjectFactory extends ObjectFactory implements ApplicationContextAware {
     private static final Log log = LogFactory.getLog(SpringObjectFactory.class);
     }
 
     public Class getClassInstance(String className) throws ClassNotFoundException {
-        Class clazz = null;
-        if (useClassCache) {
-            // this cache of classes is needed because Spring sucks at dealing with situations where the
-            // class instance changes (such as WebWork's QuickStart)
-            clazz = (Class) classes.get(className);
-        }
-
-        if (clazz == null) {
-            if (appContext.containsBean(className)) {
-                clazz = appContext.getBean(className).getClass();
-            } else {
-                clazz = super.getClassInstance(className);
+        synchronized(classes) { // protect HashMap (classes) from concurrent read/write
+            Class clazz = null;
+            if (useClassCache) {
+                // this cache of classes is needed because Spring sucks at dealing with situations where the
+                // class instance changes (such as WebWork's QuickStart)
+                clazz = (Class) classes.get(className);
             }
 
-            if (useClassCache) {
-                classes.put(className, clazz);
+            if (clazz == null) {
+                if (appContext.containsBean(className)) {
+                    clazz = appContext.getBean(className).getClass();
+                } else {
+                    clazz = super.getClassInstance(className);
+                }
+
+                if (useClassCache) {
+                    classes.put(className, clazz);
+                }
             }
-        }
 
-        return clazz;
+            return clazz;
+        }
     }
 
     /**