Author: kkolinko Date: Sat Jun 21 17:23:18 2014 New Revision: 1604435 URL: http://svn.apache.org/r1604435 Log: Make sure that context.versions array always has at least 1 element. Do not assign 0-length array to this field.
Modified: tomcat/trunk/java/org/apache/catalina/mapper/Mapper.java Modified: tomcat/trunk/java/org/apache/catalina/mapper/Mapper.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/mapper/Mapper.java?rev=1604435&r1=1604434&r2=1604435&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/mapper/Mapper.java (original) +++ tomcat/trunk/java/org/apache/catalina/mapper/Mapper.java Sat Jun 21 17:23:18 2014 @@ -212,23 +212,26 @@ public final class Mapper { MappedHost mappedHost = hostMapping.object; int slashCount = slashCount(path); synchronized (mappedHost) { + ContextVersion newContextVersion = new ContextVersion(version, + path, slashCount, context, resources); + newContextVersion.welcomeResources = welcomeResources; + MappedContext mappedContext = exactFind( mappedHost.contextList.contexts, path); if (mappedContext == null) { mappedContext = new MappedContext(path); + mappedContext.versions = new ContextVersion[] { newContextVersion }; mappedHost.contextList = mappedHost.contextList.addContext( mappedContext, slashCount); - } - - ContextVersion[] contextVersions = mappedContext.versions; - ContextVersion[] newContextVersions = new ContextVersion[contextVersions.length + 1]; - ContextVersion newContextVersion = new ContextVersion(version, - path, slashCount, context, resources); - newContextVersion.welcomeResources = welcomeResources; - if (insertMap(contextVersions, newContextVersions, - newContextVersion)) { - mappedContext.versions = newContextVersions; contextObjectToContextVersionMap.put(context, newContextVersion); + } else { + ContextVersion[] contextVersions = mappedContext.versions; + ContextVersion[] newContextVersions = new ContextVersion[contextVersions.length + 1]; + if (insertMap(contextVersions, newContextVersions, + newContextVersion)) { + mappedContext.versions = newContextVersions; + contextObjectToContextVersionMap.put(context, newContextVersion); + } } } @@ -265,12 +268,12 @@ public final class Mapper { ContextVersion[] newContextVersions = new ContextVersion[contextVersions.length - 1]; if (removeMap(contextVersions, newContextVersions, version)) { - context.versions = newContextVersions; - if (newContextVersions.length == 0) { // Remove the context mappedHost.contextList = mappedHost.contextList .removeContext(path); + } else { + context.versions = newContextVersions; } } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org