Consistent Map/Set ordering

Use LinkedHashMaps/Sets wherever exposed to users, and code tests defensively in terms of expected Map/Set ordering. Otherwise, there'll be runtime order differences between JDK 7 and JDK 8 due to internal HashMap/Set implementation differences.

Issue: SPR-9639
(cherry picked from commit 9c09a0a)
This commit is contained in:
Juergen Hoeller
2013-04-23 13:53:09 +02:00
committed by unknown
parent d0513f7521
commit 5bdd2d245c
18 changed files with 145 additions and 195 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,7 +48,7 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti
private int order = Ordered.LOWEST_PRECEDENCE;
private Set mappedHandlers;
private Set<?> mappedHandlers;
private Class[] mappedHandlerClasses;
@@ -74,7 +74,7 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti
* error view will be used as fallback for all exceptions; any further
* HandlerExceptionResolvers in the chain will be ignored in this case.
*/
public void setMappedHandlers(Set mappedHandlers) {
public void setMappedHandlers(Set<?> mappedHandlers) {
this.mappedHandlers = mappedHandlers;
}
@@ -145,7 +145,7 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti
/**
* Check whether this resolver is supposed to apply to the given handler.
* <p>The default implementation checks against the specified mapped handlers
* and handler classes, if any, and alspo checks the window state (according
* and handler classes, if any, and also checks the window state (according
* to the "renderWhenMinimize" property).
* @param request current portlet request
* @param handler the executed handler, or {@code null} if none chosen at the

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -159,7 +159,8 @@ public class SimpleMappingExceptionResolver extends AbstractHandlerExceptionReso
for (Enumeration names = exceptionMappings.propertyNames(); names.hasMoreElements();) {
String exceptionMapping = (String) names.nextElement();
int depth = getDepth(exceptionMapping, ex);
if (depth >= 0 && depth < deepest) {
if (depth >= 0 && (depth < deepest || (depth == deepest &&
dominantMapping != null && exceptionMapping.length() > dominantMapping.length()))) {
deepest = depth;
dominantMapping = exceptionMapping;
viewName = exceptionMappings.getProperty(exceptionMapping);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,6 @@ package org.springframework.web.portlet.handler;
import java.util.Collections;
import java.util.Properties;
import javax.portlet.WindowState;
import junit.framework.TestCase;
@@ -206,7 +205,7 @@ public class SimpleMappingExceptionResolverTests extends TestCase {
exceptionResolver.setMappedHandlers(Collections.singleton(handler1));
exceptionResolver.setExceptionMappings(props);
ModelAndView mav = exceptionResolver.resolveException(request, response, handler1, oddException);
assertEquals("error", mav.getViewName());
assertEquals("another-error", mav.getViewName());
}
public void testTwoMappingsThrowOddExceptionUseLongExceptionMapping() {