tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1005647 - in /tomcat/trunk: java/org/apache/catalina/core/ApplicationContext.java java/org/apache/catalina/core/StandardContext.java webapps/docs/changelog.xml
Date Thu, 07 Oct 2010 21:53:55 GMT
Author: markt
Date: Thu Oct  7 21:53:55 2010
New Revision: 1005647

URL: http://svn.apache.org/viewvc?rev=1005647&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49987
Fix thread safety issue with population of servlet context initialization parameters.

Modified:
    tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java
    tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java?rev=1005647&r1=1005646&r2=1005647&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java Thu Oct  7 21:53:55
2010
@@ -66,7 +66,6 @@ import org.apache.catalina.LifecycleStat
 import org.apache.catalina.Service;
 import org.apache.catalina.Wrapper;
 import org.apache.catalina.connector.Connector;
-import org.apache.catalina.deploy.ApplicationParameter;
 import org.apache.catalina.deploy.FilterDef;
 import org.apache.catalina.util.Enumerator;
 import org.apache.catalina.util.RequestUtil;
@@ -173,7 +172,8 @@ public class ApplicationContext
     /**
      * The merged context initialization parameters for this Context.
      */
-    private Map<String,String> parameters = null;
+    private Map<String,String> parameters =
+        new ConcurrentHashMap<String,String>();
 
 
     /**
@@ -317,10 +317,7 @@ public class ApplicationContext
      * @param name Name of the initialization parameter to retrieve
      */
     public String getInitParameter(final String name) {
-
-        mergeParameters();
         return parameters.get(name);
-
     }
 
 
@@ -329,10 +326,7 @@ public class ApplicationContext
      * empty enumeration if the context has no initialization parameters.
      */
     public Enumeration<String> getInitParameterNames() {
-
-        mergeParameters();
         return (new Enumerator<String>(parameters.keySet()));
-
     }
 
 
@@ -1215,9 +1209,6 @@ public class ApplicationContext
 
     @Override
     public boolean setInitParameter(String name, String value) {
-        
-        mergeParameters();
-        
         if (parameters.containsKey(name)) {
             return false;
         }
@@ -1509,38 +1500,6 @@ public class ApplicationContext
         this.newServletContextListenerAllowed = allowed;
     }
     
-    // -------------------------------------------------------- Private Methods
-
-
-    /**
-     * Merge the context initialization parameters specified in the application
-     * deployment descriptor with the application parameters described in the
-     * server configuration, respecting the <code>override</code> property of
-     * the application parameters appropriately.
-     */
-    private void mergeParameters() {
-
-        if (parameters != null)
-            return;
-        Map<String,String> results = new ConcurrentHashMap<String,String>();
-        String names[] = context.findParameters();
-        for (int i = 0; i < names.length; i++)
-            results.put(names[i], context.findParameter(names[i]));
-        ApplicationParameter params[] =
-            context.findApplicationParameters();
-        for (int i = 0; i < params.length; i++) {
-            if (params[i].getOverride()) {
-                if (results.get(params[i].getName()) == null)
-                    results.put(params[i].getName(), params[i].getValue());
-            } else {
-                results.put(params[i].getName(), params[i].getValue());
-            }
-        }
-        parameters = results;
-
-    }
-
-
     /**
      * List resource paths (recursively), and store all of them in the given
      * Set.

Modified: tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardContext.java?rev=1005647&r1=1005646&r2=1005647&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardContext.java Thu Oct  7 21:53:55 2010
@@ -4770,6 +4770,9 @@ public class StandardContext extends Con
                 postWelcomeFiles();
             }
             
+            // Set up the context init params
+            mergeParameters();
+
             // Call ServletContainerInitializers
             for (Map.Entry<ServletContainerInitializer, Set<Class<?>>>
entry :
                 initializers.entrySet()) {
@@ -4896,6 +4899,36 @@ public class StandardContext extends Con
         }
     }
 
+    
+
+    /**
+     * Merge the context initialization parameters specified in the application
+     * deployment descriptor with the application parameters described in the
+     * server configuration, respecting the <code>override</code> property of
+     * the application parameters appropriately.
+     */
+    private void mergeParameters() {
+        ServletContext sc = getServletContext();
+        
+        String names[] = findParameters();
+        for (int i = 0; i < names.length; i++) {
+            sc.setInitParameter(names[i], findParameter(names[i]));
+        }
+
+        ApplicationParameter params[] = findApplicationParameters();
+        for (int i = 0; i < params.length; i++) {
+            if (params[i].getOverride()) {
+                if (sc.getInitParameter(params[i].getName()) == null) {
+                    sc.setInitParameter(params[i].getName(),
+                            params[i].getValue());
+                }
+            } else {
+                sc.setInitParameter(params[i].getName(), params[i].getValue());
+            }
+        }
+    }
+
+
     /**
      * Stop this component and implement the requirements
      * of {@link LifecycleBase#stopInternal()}.

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1005647&r1=1005646&r2=1005647&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Thu Oct  7 21:53:55 2010
@@ -81,6 +81,10 @@
         than throwing an exception and failing to start, allow thw web
         application to start normally. (mark)
       </fix>
+      <fix>
+        <bug>49987</bug>: Fix thread safety issue with population of servlet
+        context initialization parameters. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message