HttpEntity and its subclasses insist on same target type for equality

Issue: SPR-12910
This commit is contained in:
Juergen Hoeller
2015-04-15 14:58:16 +02:00
parent 8b2d9951e0
commit af272c2124
6 changed files with 47 additions and 17 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@@ -22,7 +22,8 @@ import org.springframework.util.ObjectUtils;
/**
* Represents an HTTP request or response entity, consisting of headers and body.
*
* <p>Typically used in combination with the {@link org.springframework.web.client.RestTemplate RestTemplate}, like so:
* <p>Typically used in combination with the {@link org.springframework.web.client.RestTemplate},
* like so:
* <pre class="code">
* HttpHeaders headers = new HttpHeaders();
* headers.setContentType(MediaType.TEXT_PLAIN);
@@ -46,6 +47,7 @@ import org.springframework.util.ObjectUtils;
* </pre>
*
* @author Arjen Poutsma
* @author Juergen Hoeller
* @since 3.0.2
* @see org.springframework.web.client.RestTemplate
* @see #getBody()
@@ -123,12 +125,13 @@ public class HttpEntity<T> {
return (this.body != null);
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof HttpEntity)) {
if (other == null || !other.getClass().equals(getClass())) {
return false;
}
HttpEntity<?> otherEntity = (HttpEntity<?>) other;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@@ -133,7 +133,7 @@ public class RequestEntity<T> extends HttpEntity<T> {
if (this == other) {
return true;
}
if (!(other instanceof RequestEntity) || !super.equals(other)) {
if (!super.equals(other)) {
return false;
}
RequestEntity<?> otherEntity = (RequestEntity<?>) other;

View File

@@ -117,12 +117,13 @@ public class ResponseEntity<T> extends HttpEntity<T> {
return this.statusCode;
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof ResponseEntity) || !super.equals(other)) {
if (!super.equals(other)) {
return false;
}
ResponseEntity<?> otherEntity = (ResponseEntity<?>) other;