MessageHeaders now copies the Map passed into its constructor to enforce immutability of the Map itself (note: mutability of the values in the Map is intentionally left as a development decision). The clear() method now correctly throws UnsupportedOperationException along with the other Map methods that would otherwise be capable of modifying the Map (INT-427).
This commit is contained in:
@@ -55,8 +55,9 @@ public final class MessageHeaders implements Map<String, Object>, Serializable {
|
||||
|
||||
|
||||
public MessageHeaders(Map<String, Object> headers) {
|
||||
this.headers = (headers != null ? headers
|
||||
: new HashMap<String, Object>());
|
||||
this.headers = (headers != null)
|
||||
? new HashMap<String, Object>(headers)
|
||||
: new HashMap<String, Object>();
|
||||
this.headers.put(ID, UUID.randomUUID());
|
||||
this.headers.put(TIMESTAMP, new Long(System.currentTimeMillis()));
|
||||
}
|
||||
@@ -112,7 +113,7 @@ public final class MessageHeaders implements Map<String, Object>, Serializable {
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return headers.hashCode();
|
||||
return this.headers.hashCode();
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
@@ -134,10 +135,6 @@ public final class MessageHeaders implements Map<String, Object>, Serializable {
|
||||
* Map implementation
|
||||
*/
|
||||
|
||||
public void clear() {
|
||||
this.headers.clear();
|
||||
}
|
||||
|
||||
public boolean containsKey(Object key) {
|
||||
return this.headers.containsKey(key);
|
||||
}
|
||||
@@ -186,4 +183,8 @@ public final class MessageHeaders implements Map<String, Object>, Serializable {
|
||||
throw new UnsupportedOperationException("MessageHeaders is immutable.");
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
throw new UnsupportedOperationException("MessageHeaders is immutable.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user