From 0e490407076b28e429d339738a9260978711a464 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Tue, 19 Aug 2014 15:16:41 -0400 Subject: [PATCH] Fix hashcode/equals issue in HeadersRequestCondition --- .../mvc/condition/AbstractNameValueExpression.java | 10 +++++++--- .../mvc/condition/HeadersRequestCondition.java | 13 +++++-------- .../mvc/condition/ParamsRequestCondition.java | 5 +++++ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractNameValueExpression.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractNameValueExpression.java index 74c18e86cc..3d84a0ed33 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractNameValueExpression.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractNameValueExpression.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2014 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. @@ -64,6 +64,8 @@ abstract class AbstractNameValueExpression implements NameValueExpression return this.isNegated; } + protected abstract boolean isCaseSensitiveName(); + protected abstract T parseValue(String valueExpression); public final boolean match(HttpServletRequest request) { @@ -88,7 +90,9 @@ abstract class AbstractNameValueExpression implements NameValueExpression } if (obj != null && obj instanceof AbstractNameValueExpression) { AbstractNameValueExpression other = (AbstractNameValueExpression) obj; - return ((this.name.equalsIgnoreCase(other.name)) && + String thisName = isCaseSensitiveName() ? this.name : this.name.toLowerCase(); + String otherName = isCaseSensitiveName() ? other.name : other.name.toLowerCase(); + return ((thisName.equalsIgnoreCase(otherName)) && (this.value != null ? this.value.equals(other.value) : other.value == null) && this.isNegated == other.isNegated); } @@ -97,7 +101,7 @@ abstract class AbstractNameValueExpression implements NameValueExpression @Override public int hashCode() { - int result = name.hashCode(); + int result = isCaseSensitiveName() ? name.hashCode() : name.toLowerCase().hashCode(); result = 31 * result + (value != null ? value.hashCode() : 0); result = 31 * result + (isNegated ? 1 : 0); return result; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/HeadersRequestCondition.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/HeadersRequestCondition.java index 0238d656cc..ffa47be0f0 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/HeadersRequestCondition.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/HeadersRequestCondition.java @@ -139,6 +139,11 @@ public final class HeadersRequestCondition extends AbstractRequestCondition