Index: http-utils/src/main/java/com/sun/grizzly/util/http/mapper/Mapper.java =================================================================== --- http-utils/src/main/java/com/sun/grizzly/util/http/mapper/Mapper.java (revision 1417) +++ http-utils/src/main/java/com/sun/grizzly/util/http/mapper/Mapper.java (working copy) @@ -182,9 +182,14 @@ newHost.defaultContexts = defaultContexts; newHost.defaultContextPaths = defaultContextPaths; // END GlassFish 1024 - if (insertMap(hosts, newHosts, newHost)) { + Host oldElem = (Host) insertMap(hosts, newHosts, newHost); + if (oldElem == null) { hosts = newHosts; - } + } else if (allowReplacement) { + oldElem.object = host; + contextList = oldElem.contextList; + } + for (int i = 0; i < aliases.length; i++) { newHosts = new Host[hosts.length + 1]; newHost = new Host(); @@ -195,7 +200,7 @@ newHost.defaultContextPaths = defaultContextPaths; // END GlassFish 1024 newHost.object = host; - if (insertMap(hosts, newHosts, newHost)) { + if (insertMap(hosts, newHosts, newHost) == null) { hosts = newHosts; } } @@ -299,7 +304,7 @@ newContext.object = context; newContext.welcomeResources = welcomeResources; newContext.resources = resources; - if (insertMap(contexts, newContexts, newContext)) { + if (insertMap(contexts, newContexts, newContext) == null) { host.contextList.contexts = newContexts; // START GlassFish 1024 if (path.equals(host.defaultContextPaths[0])) { @@ -447,7 +452,7 @@ Wrapper[] oldWrappers = context.wildcardWrappers; Wrapper[] newWrappers = new Wrapper[oldWrappers.length + 1]; - if (insertMap(oldWrappers, newWrappers, newWrapper)) { + if (insertMap(oldWrappers, newWrappers, newWrapper) == null) { context.wildcardWrappers = newWrappers; int slashCount = slashCount(newWrapper.name); if (slashCount > context.nesting) { @@ -460,7 +465,7 @@ Wrapper[] oldWrappers = context.extensionWrappers; Wrapper[] newWrappers = new Wrapper[oldWrappers.length + 1]; - if (insertMap(oldWrappers, newWrappers, newWrapper)) { + if (insertMap(oldWrappers, newWrappers, newWrapper) == null) { context.extensionWrappers = newWrappers; } } else if (path.equals("/")) { @@ -473,7 +478,7 @@ Wrapper[] oldWrappers = context.exactWrappers; Wrapper[] newWrappers = new Wrapper[oldWrappers.length + 1]; - if (insertMap(oldWrappers, newWrappers, newWrapper)) { + if (insertMap(oldWrappers, newWrappers, newWrapper) == null) { context.exactWrappers = newWrappers; } } @@ -1403,23 +1408,25 @@ /** - * Insert into the right place in a sorted MapElement array, and prevent - * duplicates only if {@link #allowReplacement} is false + * Insert into the right place in a sorted MapElement array, preventing + * duplicates. + * + * @return old MapElement with matching name (this is an indication that + * newElement has not been inserted), or null if oldMap did not contain + * any MapElement with matching name (this is an indication that + * newElement has been inserted) */ - private static final boolean insertMap + private static final MapElement insertMap (MapElement[] oldMap, MapElement[] newMap, MapElement newElement) { int pos = find(oldMap, newElement.name); if ((pos != -1) && (newElement.name.equals(oldMap[pos].name))) { - if (allowReplacement){ - oldMap[pos].object = newElement.object; - } - return false; + return oldMap[pos]; } System.arraycopy(oldMap, 0, newMap, 0, pos + 1); newMap[pos + 1] = newElement; System.arraycopy (oldMap, pos + 1, newMap, pos + 2, oldMap.length - pos - 1); - return true; + return null; }