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

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


The following commit(s) were added to refs/heads/main by this push:
     new 294daa0ff6 ARTEMIS-4162 Remove EMPTY_ROUTING_TYPES from AddressInfo
294daa0ff6 is described below

commit 294daa0ff6a608813694818812d2a4a1a7702146
Author: Clebert Suconic <[email protected]>
AuthorDate: Fri Mar 10 04:35:48 2023 -0500

    ARTEMIS-4162 Remove EMPTY_ROUTING_TYPES from AddressInfo
    
    I have seen a werid intermittent failure in the testsuite
    caused by some race where the EMPTY_SET ends up Not Empty! Causing weird 
failures that were really difficult to be investigated
---
 .../activemq/artemis/core/server/impl/AddressInfo.java    | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AddressInfo.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AddressInfo.java
index 2e4749a5d6..311a77c14c 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AddressInfo.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AddressInfo.java
@@ -59,8 +59,13 @@ public class AddressInfo {
 
    private volatile boolean temporary = false;
 
-   private static final EnumSet<RoutingType> EMPTY_ROUTING_TYPES = 
EnumSet.noneOf(RoutingType.class);
-   private EnumSet<RoutingType> routingTypes;
+   // Do not be tempted to cache this on an static variable.
+   // if the empty set gets damaged in any race, the results and unpredictable
+   private static EnumSet<RoutingType> createEmptySet() {
+      return EnumSet.noneOf(RoutingType.class);
+   }
+
+   EnumSet<RoutingType> routingTypes;
    private RoutingType firstSeen;
 
    private boolean internal = false;
@@ -97,11 +102,11 @@ public class AddressInfo {
    }
 
    public AddressInfo(String name) {
-      this(SimpleString.toSimpleString(name), EMPTY_ROUTING_TYPES);
+      this(SimpleString.toSimpleString(name), createEmptySet());
    }
 
    public AddressInfo(SimpleString name) {
-      this(name, EMPTY_ROUTING_TYPES);
+      this(name, createEmptySet());
    }
 
    /**
@@ -157,7 +162,7 @@ public class AddressInfo {
    }
 
    public EnumSet<RoutingType> getRoutingTypes() {
-      return routingTypes == null ? EMPTY_ROUTING_TYPES : routingTypes;
+      return routingTypes == null ? createEmptySet() : routingTypes;
    }
 
    public AddressInfo setRoutingTypes(final EnumSet<RoutingType> routingTypes) 
{

Reply via email to