This is an automated email from the ASF dual-hosted git repository.

clebertsuconic pushed a commit to branch 2.19.x
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git

commit 570fd6c7af3e735f9b3133c336d9f8a41c446b04
Author: Domenico Francesco Bruscino <[email protected]>
AuthorDate: Thu Oct 21 14:46:51 2021 +0200

    ARTEMIS-3363 Fix TransportConfiguration extraParams equals
    
    (cherry picked from commit 14f8e8d5abeb8417f177763edab7982f312a5e0f)
---
 .../artemis/api/core/TransportConfiguration.java       |  5 ++---
 .../artemis/api/core/TransportConfigurationTest.java   | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+), 3 deletions(-)

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 609b9c1..15a3b52 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 0f02e90..bb39418 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
@@ -68,6 +68,24 @@ public class TransportConfigurationTest {
    }
 
    @Test
+   public void testExtraParamsEquals() {
+      final String name = "";
+      final String className = this.getClass().getName();
+      final Map<String, Object> params = Collections.emptyMap();
+      final Map<String, Object> 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<String, Object> params = new HashMap<>();
       params.put(TransportConstants.TRUSTSTORE_PASSWORD_PROP_NAME, 
"secret_password");

Reply via email to