From 905f76116f20b2121e940c4ee1f297b1d479c706 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Wed, 15 Oct 2008 19:38:53 +0000 Subject: [PATCH] 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). --- .../integration/core/MessageHeaders.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/core/MessageHeaders.java b/org.springframework.integration/src/main/java/org/springframework/integration/core/MessageHeaders.java index 8b66e1fcc2..95e7acb759 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/core/MessageHeaders.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/core/MessageHeaders.java @@ -55,8 +55,9 @@ public final class MessageHeaders implements Map, Serializable { public MessageHeaders(Map headers) { - this.headers = (headers != null ? headers - : new HashMap()); + this.headers = (headers != null) + ? new HashMap(headers) + : new HashMap(); this.headers.put(ID, UUID.randomUUID()); this.headers.put(TIMESTAMP, new Long(System.currentTimeMillis())); } @@ -112,7 +113,7 @@ public final class MessageHeaders implements Map, 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, 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, Serializable { throw new UnsupportedOperationException("MessageHeaders is immutable."); } + public void clear() { + throw new UnsupportedOperationException("MessageHeaders is immutable."); + } + }