From 64ee5e579adcec97122fc0ee1414031da3be0c6e Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Mon, 2 Apr 2012 15:19:38 -0400 Subject: [PATCH] Fix bug with custom RequestCondition A custom RequestCondition which can be provided by overriding methods in RequestMappingHandlerMapping worked only for conditions that match and did not return null (as it should have) for conditions that don't match. Issues: SPR-9134 --- .../mvc/condition/RequestConditionHolder.java | 26 ++++++++-------- .../RequestConditionHolderTests.java | 31 ++++++++++++------- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/RequestConditionHolder.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/RequestConditionHolder.java index 3de3a9abb54..b28fef5f175 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/RequestConditionHolder.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/RequestConditionHolder.java @@ -25,12 +25,12 @@ import javax.servlet.http.HttpServletRequest; /** * A holder for a {@link RequestCondition} useful when the type of the held * request condition is not known ahead of time - e.g. custom condition. - * - *

An implementation of {@code RequestCondition} itself, a - * {@code RequestConditionHolder} decorates the held request condition allowing - * it to be combined and compared with other custom request conditions while + * + *

An implementation of {@code RequestCondition} itself, a + * {@code RequestConditionHolder} decorates the held request condition allowing + * it to be combined and compared with other custom request conditions while * ensuring type and null safety. - * + * * @author Rossen Stoyanchev * @since 3.1 */ @@ -38,9 +38,9 @@ public final class RequestConditionHolder extends AbstractRequestCondition requestCondition) { @@ -65,7 +65,7 @@ public final class RequestConditionHolder extends AbstractRequestCondition match = (RequestCondition) condition.getMatchingCondition(request); - return new RequestConditionHolder(match); + return (match != null) ? new RequestConditionHolder(match) : null; } /** - * Compare the request conditions held by the two RequestConditionHolder + * Compare the request conditions held by the two RequestConditionHolder * instances after making sure the conditions are of the same type. * Or if one holder is empty, the other holder is preferred. */ @@ -132,5 +132,5 @@ public final class RequestConditionHolder extends AbstractRequestCondition