diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/TransportConfiguration.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/TransportConfiguration.java index 609b9c1c60..15a3b522be 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/TransportConfiguration.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/TransportConfiguration.java @@ -222,9 +222,8 @@ public class TransportConfiguration implements Serializable { return false; } - // Empty and null extraProps maps are equivalent so the condition to check if two extraProps maps are equal is: - // (extraProps == that.extraProps) || (extraProps != null && ((extraProps.isEmpty() && that.extraProps == null) || extraProps.equals(that.extraProps))) - if ((extraProps != that.extraProps) && (extraProps == null || ((!extraProps.isEmpty() || that.extraProps != null) && !extraProps.equals(that.extraProps)))) { + // Empty and null extraProps maps are equivalent so the condition to check if two extraProps maps are not equal is: + if ((extraProps != that.extraProps) && (extraProps != null || !that.extraProps.isEmpty()) && (that.extraProps != null || !extraProps.isEmpty()) && (extraProps == null || that.extraProps == null || !extraProps.equals(that.extraProps))) { return false; } diff --git a/artemis-core-client/src/test/java/org/apache/activemq/artemis/api/core/TransportConfigurationTest.java b/artemis-core-client/src/test/java/org/apache/activemq/artemis/api/core/TransportConfigurationTest.java index 0f02e90a7b..bb39418064 100644 --- a/artemis-core-client/src/test/java/org/apache/activemq/artemis/api/core/TransportConfigurationTest.java +++ b/artemis-core-client/src/test/java/org/apache/activemq/artemis/api/core/TransportConfigurationTest.java @@ -67,6 +67,24 @@ public class TransportConfigurationTest { } + @Test + public void testExtraParamsEquals() { + final String name = ""; + final String className = this.getClass().getName(); + final Map params = Collections.emptyMap(); + final Map extraParams = Collections.singletonMap("key", "foo"); + + Assert.assertEquals(new TransportConfiguration(className, params, name, null), new TransportConfiguration(className, params, name, null)); + Assert.assertEquals(new TransportConfiguration(className, params, name, null), new TransportConfiguration(className, params, name, Collections.emptyMap())); + Assert.assertEquals(new TransportConfiguration(className, params, name, Collections.emptyMap()), new TransportConfiguration(className, params, name, null)); + Assert.assertEquals(new TransportConfiguration(className, params, name, extraParams), new TransportConfiguration(className, params, name, extraParams)); + Assert.assertEquals(new TransportConfiguration(className, params, name, extraParams), new TransportConfiguration(className, params, name, new HashMap<>(extraParams))); + + Assert.assertNotEquals(new TransportConfiguration(className, params, name, null), new TransportConfiguration(className, params, name, extraParams)); + Assert.assertNotEquals(new TransportConfiguration(className, params, name, Collections.emptyMap()), new TransportConfiguration(className, params, name, extraParams)); + Assert.assertNotEquals(new TransportConfiguration(className, params, name, extraParams), new TransportConfiguration(className, params, name, Collections.singletonMap("key", "too"))); + } + @Test public void testToStringObfuscatesPasswords() { HashMap params = new HashMap<>();