ensure that the return values are unmodifiable
Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/19ea818b Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/19ea818b Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/19ea818b Branch: refs/heads/master Commit: 19ea818b76151ea731c55dcfeba0f5715baf611c Parents: 909ea19 Author: Robert Gemmell <[email protected]> Authored: Mon Feb 2 12:19:23 2015 +0000 Committer: Robert Gemmell <[email protected]> Committed: Mon Feb 2 12:19:23 2015 +0000 ---------------------------------------------------------------------- .../org/apache/qpid/jms/JmsConnectionFactory.java | 16 +++++----------- .../java/org/apache/qpid/jms/JmsDestination.java | 9 ++------- .../java/org/apache/qpid/jms/jndi/JNDIStorable.java | 4 ++-- .../apache/qpid/jms/JmsConnectionFactoryTest.java | 16 +++++++++++++++- .../test/java/org/apache/qpid/jms/JmsQueueTest.java | 16 +++++++++++++++- .../org/apache/qpid/jms/JmsTemporaryQueueTest.java | 16 +++++++++++++++- .../org/apache/qpid/jms/JmsTemporaryTopicTest.java | 16 +++++++++++++++- .../test/java/org/apache/qpid/jms/JmsTopicTest.java | 16 +++++++++++++++- 8 files changed, 84 insertions(+), 25 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/19ea818b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionFactory.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionFactory.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionFactory.java index e196fbd..7f84de4 100644 --- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionFactory.java +++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionFactory.java @@ -102,30 +102,24 @@ public class JmsConnectionFactory extends JNDIStorable implements ConnectionFact setRemoteURI(remoteURI); } - /** - * @param map - */ @Override - protected Map<String, String> buildFromProperties(Map<String, String> map) { + protected Map<String, String> buildFromProperties(Map<String, String> props) { // Apply the remoteURI in a consistent order before // any other properties, since as it may contain // some options within it. - String remoteURI = map.remove(REMOTE_URI_PROP); + String remoteURI = props.remove(REMOTE_URI_PROP); if (remoteURI != null) { setRemoteURI(remoteURI); } - return PropertyUtil.setProperties(this, map); + return PropertyUtil.setProperties(this, props); } - /** - * @param map - */ @Override - protected void populateProperties(Map<String, String> map) { + protected void populateProperties(Map<String, String> props) { try { Map<String, String> result = PropertyUtil.getProperties(this); - map.putAll(result); + props.putAll(result); } catch (Exception e) { e.printStackTrace(); } http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/19ea818b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsDestination.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsDestination.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsDestination.java index 0402bd7..ff08c44 100644 --- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsDestination.java +++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsDestination.java @@ -20,6 +20,7 @@ import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; +import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -80,9 +81,6 @@ public abstract class JmsDestination extends JNDIStorable implements Externaliza return !this.topic; } - /** - * @param props - */ @Override protected Map<String, String> buildFromProperties(Map<String, String> props) { setName(getProperty(props, NAME_PROP, "")); @@ -90,12 +88,9 @@ public abstract class JmsDestination extends JNDIStorable implements Externaliza Map<String, String> unused = new HashMap<String,String>(props); unused.remove(NAME_PROP); - return unused; + return Collections.unmodifiableMap(unused); } - /** - * @param props - */ @Override protected void populateProperties(Map<String, String> props) { props.put(NAME_PROP, getName()); http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/19ea818b/qpid-jms-client/src/main/java/org/apache/qpid/jms/jndi/JNDIStorable.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/jndi/JNDIStorable.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/jndi/JNDIStorable.java index d17c1bc..8753fcc 100644 --- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/jndi/JNDIStorable.java +++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/jndi/JNDIStorable.java @@ -38,7 +38,7 @@ public abstract class JNDIStorable implements Referenceable, Externalizable { * Set the properties that will represent the instance in JNDI * * @param props - * @return a new map containing any unused properties, or an empty map if they were all used. + * @return a new, unmodifiable, map containing any unused properties, or empty if none were. */ protected abstract Map<String, String> buildFromProperties(Map<String, String> props); @@ -53,7 +53,7 @@ public abstract class JNDIStorable implements Referenceable, Externalizable { * set the properties for this instance as retrieved from JNDI * * @param props - * @return a new map containing any unused properties, or an empty map if they were all used. + * @return a new, unmodifiable, map containing any unused properties, or empty if none were. */ public synchronized Map<String, String> setProperties(Map<String, String> props) { return buildFromProperties(props); http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/19ea818b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionFactoryTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionFactoryTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionFactoryTest.java index d2014b2..baae401 100644 --- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionFactoryTest.java +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionFactoryTest.java @@ -132,8 +132,14 @@ public class JmsConnectionFactoryTest extends QpidJmsTestCase { // Verify the URI was filtered to remove the applied options assertEquals("URI was filtered to remove options that were applied", baseUri, cf.getRemoteURI()); - // Verify the returned map was empty + // Verify the returned map was empty and unmodifiable assertTrue("Map should be empty: " + unusedProps, unusedProps.isEmpty()); + try { + unusedProps.put("a", "b"); + fail("Map should be unmodifiable"); + } catch (UnsupportedOperationException uoe) { + // expected + } } @Test @@ -163,6 +169,14 @@ public class JmsConnectionFactoryTest extends QpidJmsTestCase { assertEquals("Unexpected size of return map", 1, unusedProps.size()); assertTrue("Expected property not found in map: " + unusedProps, unusedProps.containsKey(unusedKey)); assertEquals("Unexpected property value", unusedValue, unusedProps.get(unusedKey)); + + // Verify the returned map was unmodifiable + try { + unusedProps.put("a", "b"); + fail("Map should be unmodifiable"); + } catch (UnsupportedOperationException uoe) { + // expected + } } @Test http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/19ea818b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsQueueTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsQueueTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsQueueTest.java index b5a59b4..ed8787d 100644 --- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsQueueTest.java +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsQueueTest.java @@ -120,8 +120,14 @@ public class JmsQueueTest extends QpidJmsTestCase { assertEquals("Unexpected value for name", name, queue.getQueueName()); - // Verify the returned map was empty + // Verify the returned map was empty and unmodifiable assertTrue("Map should be empty: " + unusedProps, unusedProps.isEmpty()); + try { + unusedProps.put("a", "b"); + fail("Map should be unmodifiable"); + } catch (UnsupportedOperationException uoe) { + // expected + } } @Test @@ -144,6 +150,14 @@ public class JmsQueueTest extends QpidJmsTestCase { assertEquals("Unexpected size of return map", 1, unusedProps.size()); assertTrue("Expected property not found in map: " + unusedProps, unusedProps.containsKey(unusedKey)); assertEquals("Unexpected property value", unusedValue, unusedProps.get(unusedKey)); + + // Verify the returned map was unmodifiable + try { + unusedProps.put("a", "b"); + fail("Map should be unmodifiable"); + } catch (UnsupportedOperationException uoe) { + // expected + } } @Test http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/19ea818b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsTemporaryQueueTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsTemporaryQueueTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsTemporaryQueueTest.java index 41f1b30..93ae0ea 100644 --- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsTemporaryQueueTest.java +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsTemporaryQueueTest.java @@ -128,8 +128,14 @@ public class JmsTemporaryQueueTest extends QpidJmsTestCase { assertEquals("Unexpected value for name", name, queue.getQueueName()); - // Verify the returned map was empty + // Verify the returned map was empty and unmodifiable assertTrue("Map should be empty: " + unusedProps, unusedProps.isEmpty()); + try { + unusedProps.put("a", "b"); + fail("Map should be unmodifiable"); + } catch (UnsupportedOperationException uoe) { + // expected + } } @Test @@ -152,6 +158,14 @@ public class JmsTemporaryQueueTest extends QpidJmsTestCase { assertEquals("Unexpected size of return map", 1, unusedProps.size()); assertTrue("Expected property not found in map: " + unusedProps, unusedProps.containsKey(unusedKey)); assertEquals("Unexpected property value", unusedValue, unusedProps.get(unusedKey)); + + // Verify the returned map was unmodifiable + try { + unusedProps.put("a", "b"); + fail("Map should be unmodifiable"); + } catch (UnsupportedOperationException uoe) { + // expected + } } @Test http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/19ea818b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsTemporaryTopicTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsTemporaryTopicTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsTemporaryTopicTest.java index 8025060..5cd0be1 100644 --- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsTemporaryTopicTest.java +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsTemporaryTopicTest.java @@ -128,8 +128,14 @@ public class JmsTemporaryTopicTest extends QpidJmsTestCase { assertEquals("Unexpected value for name", name, topic.getTopicName()); - // Verify the returned map was empty + // Verify the returned map was empty and unmodifiable assertTrue("Map should be empty: " + unusedProps, unusedProps.isEmpty()); + try { + unusedProps.put("a", "b"); + fail("Map should be unmodifiable"); + } catch (UnsupportedOperationException uoe) { + // expected + } } @Test @@ -152,6 +158,14 @@ public class JmsTemporaryTopicTest extends QpidJmsTestCase { assertEquals("Unexpected size of return map", 1, unusedProps.size()); assertTrue("Expected property not found in map: " + unusedProps, unusedProps.containsKey(unusedKey)); assertEquals("Unexpected property value", unusedValue, unusedProps.get(unusedKey)); + + // Verify the returned map was unmodifiable + try { + unusedProps.put("a", "b"); + fail("Map should be unmodifiable"); + } catch (UnsupportedOperationException uoe) { + // expected + } } @Test http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/19ea818b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsTopicTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsTopicTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsTopicTest.java index 408ad9f..702e82b 100644 --- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsTopicTest.java +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsTopicTest.java @@ -120,8 +120,14 @@ public class JmsTopicTest extends QpidJmsTestCase { assertEquals("Unexpected value for name", name, topic.getTopicName()); - // Verify the returned map was empty + // Verify the returned map was empty and unmodifiable assertTrue("Map should be empty: " + unusedProps, unusedProps.isEmpty()); + try { + unusedProps.put("a", "b"); + fail("Map should be unmodifiable"); + } catch (UnsupportedOperationException uoe) { + // expected + } } @Test @@ -144,6 +150,14 @@ public class JmsTopicTest extends QpidJmsTestCase { assertEquals("Unexpected size of return map", 1, unusedProps.size()); assertTrue("Expected property not found in map: " + unusedProps, unusedProps.containsKey(unusedKey)); assertEquals("Unexpected property value", unusedValue, unusedProps.get(unusedKey)); + + // Verify the returned map was unmodifiable + try { + unusedProps.put("a", "b"); + fail("Map should be unmodifiable"); + } catch (UnsupportedOperationException uoe) { + // expected + } } @Test --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
