Author: kkolinko
Date: Wed Jul  9 01:48:59 2014
New Revision: 1608983

URL: http://svn.apache.org/r1608983
Log:
For BZ 56653
Improve handling of Context.versions field.
Do not assign an empty array to this field, neither when creating a new 
versions list, nor when removing the last version from it. The mapping 
algorithm does not expect this list to be empty. Mark the versions list field 
as volatile, because it is updated when a Context is started or stopped.

This backports r1604435 and a bit from r1604320 and r1604928.

Modified:
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java?rev=1608983&r1=1608982&r2=1608983&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java 
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java 
Wed Jul  9 01:48:59 2014
@@ -237,6 +237,14 @@ public final class Mapper {
         }
         int slashCount = slashCount(path);
         synchronized (mappedHost) {
+            ContextVersion newContextVersion = new ContextVersion();
+            newContextVersion.path = path;
+            newContextVersion.slashCount = slashCount;
+            newContextVersion.name = version;
+            newContextVersion.object = context;
+            newContextVersion.welcomeResources = welcomeResources;
+            newContextVersion.resources = resources;
+
             Context[] contexts = mappedHost.contextList.contexts;
             // Update nesting
             if (slashCount > mappedHost.contextList.nesting) {
@@ -244,26 +252,18 @@ public final class Mapper {
             }
             Context mappedContext = exactFind(contexts, path);
             if (mappedContext == null) {
-                mappedContext = new Context();
-                mappedContext.name = path;
+                mappedContext = new Context(path, newContextVersion);
                 Context[] newContexts = new Context[contexts.length + 1];
                 if (insertMap(contexts, newContexts, mappedContext)) {
                     mappedHost.contextList.contexts = newContexts;
                 }
-            }
-
-            ContextVersion[] contextVersions = mappedContext.versions;
-            ContextVersion[] newContextVersions =
-                new ContextVersion[contextVersions.length + 1];
-            ContextVersion newContextVersion = new ContextVersion();
-            newContextVersion.path = path;
-            newContextVersion.slashCount = slashCount;
-            newContextVersion.name = version;
-            newContextVersion.object = context;
-            newContextVersion.welcomeResources = welcomeResources;
-            newContextVersion.resources = resources;
-            if (insertMap(contextVersions, newContextVersions, 
newContextVersion)) {
-                mappedContext.versions = newContextVersions;
+            } else {
+                ContextVersion[] contextVersions = mappedContext.versions;
+                ContextVersion[] newContextVersions =
+                    new ContextVersion[contextVersions.length + 1];
+                if (insertMap(contextVersions, newContextVersions, 
newContextVersion)) {
+                    mappedContext.versions = newContextVersions;
+                }
             }
         }
 
@@ -294,8 +294,6 @@ public final class Mapper {
             ContextVersion[] newContextVersions =
                 new ContextVersion[contextVersions.length - 1];
             if (removeMap(contextVersions, newContextVersions, version)) {
-                context.versions = newContextVersions;
-
                 if (context.versions.length == 0) {
                     // Remove the context
                     Context[] newContexts = new Context[contexts.length -1];
@@ -310,6 +308,8 @@ public final class Mapper {
                             }
                         }
                     }
+                } else {
+                    context.versions = newContextVersions;
                 }
             }
         }
@@ -1542,7 +1542,12 @@ public final class Mapper {
 
 
     protected static final class Context extends MapElement {
-        public ContextVersion[] versions = new ContextVersion[0];
+        public volatile ContextVersion[] versions;
+
+        public Context(String name, ContextVersion firstVersion) {
+            super(name, null);
+            versions = new ContextVersion[] { firstVersion };
+        }
     }
 
 



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

Reply via email to