https://issues.apache.org/jira/browse/AMQ-5211
Throw an exception if the destination name is empty. Project: http://git-wip-us.apache.org/repos/asf/activemq/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/23cfa4e3 Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/23cfa4e3 Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/23cfa4e3 Branch: refs/heads/activemq-5.10.x Commit: 23cfa4e373ca55d03da25db45bc6106bc43afbdd Parents: 7536983 Author: Timothy Bish <[email protected]> Authored: Fri Jun 6 12:04:46 2014 -0400 Committer: Hadrian Zbarcea <[email protected]> Committed: Mon Dec 15 16:37:52 2014 -0500 ---------------------------------------------------------------------- .../activemq/command/ActiveMQDestination.java | 75 +++++++++++--------- .../command/ActiveMQDestinationTest.java | 25 +++++-- 2 files changed, 64 insertions(+), 36 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq/blob/23cfa4e3/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQDestination.java ---------------------------------------------------------------------- diff --git a/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQDestination.java b/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQDestination.java index 0cea4e5..bb80a8e 100755 --- a/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQDestination.java +++ b/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQDestination.java @@ -42,7 +42,6 @@ import org.apache.activemq.util.URISupport; /** * @openwire:marshaller - * */ public abstract class ActiveMQDestination extends JNDIBaseStorable implements DataStructure, Destination, Externalizable, Comparable<Object> { @@ -85,7 +84,6 @@ public abstract class ActiveMQDestination extends JNDIBaseStorable implements Da setCompositeDestinations(composites); } - // static helper methods for working with destinations // ------------------------------------------------------------------------- public static ActiveMQDestination createDestination(String name, byte defaultType) { @@ -100,16 +98,16 @@ public abstract class ActiveMQDestination extends JNDIBaseStorable implements Da } switch (defaultType) { - case QUEUE_TYPE: - return new ActiveMQQueue(name); - case TOPIC_TYPE: - return new ActiveMQTopic(name); - case TEMP_QUEUE_TYPE: - return new ActiveMQTempQueue(name); - case TEMP_TOPIC_TYPE: - return new ActiveMQTempTopic(name); - default: - throw new IllegalArgumentException("Invalid default destination type: " + defaultType); + case QUEUE_TYPE: + return new ActiveMQQueue(name); + case TOPIC_TYPE: + return new ActiveMQTopic(name); + case TEMP_QUEUE_TYPE: + return new ActiveMQTempQueue(name); + case TEMP_TOPIC_TYPE: + return new ActiveMQTempTopic(name); + default: + throw new IllegalArgumentException("Invalid default destination type: " + defaultType); } } @@ -118,7 +116,7 @@ public abstract class ActiveMQDestination extends JNDIBaseStorable implements Da return null; } if (dest instanceof ActiveMQDestination) { - return (ActiveMQDestination)dest; + return (ActiveMQDestination) dest; } if (dest instanceof Queue && dest instanceof Topic) { @@ -133,16 +131,16 @@ public abstract class ActiveMQDestination extends JNDIBaseStorable implements Da } } if (dest instanceof TemporaryQueue) { - return new ActiveMQTempQueue(((TemporaryQueue)dest).getQueueName()); + return new ActiveMQTempQueue(((TemporaryQueue) dest).getQueueName()); } if (dest instanceof TemporaryTopic) { - return new ActiveMQTempTopic(((TemporaryTopic)dest).getTopicName()); + return new ActiveMQTempTopic(((TemporaryTopic) dest).getTopicName()); } if (dest instanceof Queue) { - return new ActiveMQQueue(((Queue)dest).getQueueName()); + return new ActiveMQQueue(((Queue) dest).getQueueName()); } if (dest instanceof Topic) { - return new ActiveMQTopic(((Topic)dest).getTopicName()); + return new ActiveMQTopic(((Topic) dest).getTopicName()); } throw new JMSException("Could not transform the destination into a ActiveMQ destination: " + dest); } @@ -167,7 +165,7 @@ public abstract class ActiveMQDestination extends JNDIBaseStorable implements Da @Override public int compareTo(Object that) { if (that instanceof ActiveMQDestination) { - return compare(this, (ActiveMQDestination)that); + return compare(this, (ActiveMQDestination) that); } if (that == null) { return 1; @@ -222,11 +220,16 @@ public abstract class ActiveMQDestination extends JNDIBaseStorable implements Da public void setPhysicalName(String physicalName) { physicalName = physicalName.trim(); - final int len = physicalName.length(); + final int length = physicalName.length(); + + if (physicalName.isEmpty()) { + throw new IllegalArgumentException("Invalid destination name: a non-empty name is required"); + } + // options offset int p = -1; boolean composite = false; - for (int i = 0; i < len; i++) { + for (int i = 0; i < length; i++) { char c = physicalName.charAt(i); if (c == '?') { p = i; @@ -314,6 +317,7 @@ public abstract class ActiveMQDestination extends JNDIBaseStorable implements Da return false; } + @Override public boolean equals(Object o) { if (this == o) { return true; @@ -322,10 +326,11 @@ public abstract class ActiveMQDestination extends JNDIBaseStorable implements Da return false; } - ActiveMQDestination d = (ActiveMQDestination)o; + ActiveMQDestination d = (ActiveMQDestination) o; return physicalName.equals(d.physicalName); } + @Override public int hashCode() { if (hashValue == 0) { hashValue = physicalName.hashCode(); @@ -333,33 +338,36 @@ public abstract class ActiveMQDestination extends JNDIBaseStorable implements Da return hashValue; } + @Override public String toString() { return getQualifiedName(); } + @Override public void writeExternal(ObjectOutput out) throws IOException { out.writeUTF(this.getPhysicalName()); out.writeObject(options); } + @Override @SuppressWarnings("unchecked") public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { this.setPhysicalName(in.readUTF()); - this.options = (Map<String, String>)in.readObject(); + this.options = (Map<String, String>) in.readObject(); } public String getDestinationTypeAsString() { switch (getDestinationType()) { - case QUEUE_TYPE: - return "Queue"; - case TOPIC_TYPE: - return "Topic"; - case TEMP_QUEUE_TYPE: - return "TempQueue"; - case TEMP_TOPIC_TYPE: - return "TempTopic"; - default: - throw new IllegalArgumentException("Invalid destination type: " + getDestinationType()); + case QUEUE_TYPE: + return "Queue"; + case TOPIC_TYPE: + return "Topic"; + case TEMP_QUEUE_TYPE: + return "TempQueue"; + case TEMP_TOPIC_TYPE: + return "TempTopic"; + default: + throw new IllegalArgumentException("Invalid destination type: " + getDestinationType()); } } @@ -367,10 +375,12 @@ public abstract class ActiveMQDestination extends JNDIBaseStorable implements Da return options; } + @Override public boolean isMarshallAware() { return false; } + @Override public void buildFromProperties(Properties properties) { if (properties == null) { properties = new Properties(); @@ -379,6 +389,7 @@ public abstract class ActiveMQDestination extends JNDIBaseStorable implements Da IntrospectionSupport.setProperties(this, properties); } + @Override public void populateProperties(Properties props) { props.setProperty("physicalName", getPhysicalName()); } http://git-wip-us.apache.org/repos/asf/activemq/blob/23cfa4e3/activemq-unit-tests/src/test/java/org/apache/activemq/command/ActiveMQDestinationTest.java ---------------------------------------------------------------------- diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/command/ActiveMQDestinationTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/command/ActiveMQDestinationTest.java index 2ed668f..844be34 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/command/ActiveMQDestinationTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/command/ActiveMQDestinationTest.java @@ -36,7 +36,7 @@ public class ActiveMQDestinationTest extends DataStructureTestSupport { public ActiveMQDestination destination; - public void initCombosForTestDesintaionMarshaling() { + public void initCombosForTestDestinationMarshaling() { addCombinationValues("destination", new Object[] {new ActiveMQQueue("TEST"), new ActiveMQTopic("TEST"), new ActiveMQTempQueue("TEST:1"), @@ -49,18 +49,18 @@ public class ActiveMQDestinationTest extends DataStructureTestSupport { new ActiveMQTempTopic("TEST:1?option=value")}); } - public void testDesintaionMarshaling() throws IOException { + public void testDestinationMarshaling() throws IOException { assertBeanMarshalls(destination); } - public void initCombosForTestDesintaionOptions() { + public void initCombosForTestDestinationOptions() { addCombinationValues("destination", new Object[] {new ActiveMQQueue("TEST?k1=v1&k2=v2"), new ActiveMQTopic("TEST?k1=v1&k2=v2"), new ActiveMQTempQueue("TEST:1?k1=v1&k2=v2"), new ActiveMQTempTopic("TEST:1?k1=v1&k2=v2")}); } - public void testDesintaionOptions() throws IOException { + public void testDestinationOptions() throws IOException { Map options = destination.getOptions(); assertNotNull(options); assertEquals("v1", options.get("k1")); @@ -125,4 +125,21 @@ public class ActiveMQDestinationTest extends DataStructureTestSupport { junit.textui.TestRunner.run(suite()); } + public void testEmptyQueueName() { + try { + new ActiveMQQueue(""); + fail("Should have thrown IllegalArgumentException"); + } catch (IllegalArgumentException e) { + + } + } + + public void testEmptyTopicName() { + try { + new ActiveMQTopic(""); + fail("Should have thrown IllegalArgumentException"); + } catch (IllegalArgumentException e) { + + } + } }
