Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=41661
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 17 Jul 2009 20:12:49 +0000 (20:12 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 17 Jul 2009 20:12:49 +0000 (20:12 +0000)
Thread safety issue with JspConfig.init(). There is one JspConfig object per context and as per 41661, issues have been seen with this on real systems.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@795210 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/jasper/compiler/JspConfig.java

index 5dd3e2b..8982a25 100644 (file)
@@ -48,7 +48,7 @@ public class JspConfig {
 
     private Vector<JspPropertyGroup> jspProperties = null;
     private ServletContext ctxt;
-    private boolean initialized = false;
+    private volatile boolean initialized = false;
 
     private String defaultIsXml = null;                // unspecified
     private String defaultIsELIgnored = null;  // unspecified
@@ -218,13 +218,17 @@ public class JspConfig {
     private void init() throws JasperException {
 
         if (!initialized) {
-            processWebDotXml(ctxt);
-            defaultJspProperty = new JspProperty(defaultIsXml,
-                    defaultIsELIgnored,
-                    defaultIsScriptingInvalid,
-                    null, null, null, defaultDeferedSyntaxAllowedAsLiteral, 
-                    defaultTrimDirectiveWhitespaces);
-            initialized = true;
+            synchronized (this) {
+                if (!initialized) {
+                    processWebDotXml(ctxt);
+                    defaultJspProperty = new JspProperty(defaultIsXml,
+                            defaultIsELIgnored,
+                            defaultIsScriptingInvalid,
+                            null, null, null, defaultDeferedSyntaxAllowedAsLiteral, 
+                            defaultTrimDirectiveWhitespaces);
+                    initialized = true;
+                }
+            }
         }
     }