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 0cf94523f2..db2c67ab6b 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 @@ -32,6 +32,7 @@ public class AddressInfo { private boolean autoCreated = false; + private static final EnumSet EMPTY_ROUTING_TYPES = EnumSet.noneOf(RoutingType.class); private EnumSet routingTypes; private RoutingType firstSeen; @@ -91,26 +92,25 @@ public class AddressInfo { } public EnumSet getRoutingTypes() { - return routingTypes; + return routingTypes == null ? EMPTY_ROUTING_TYPES : routingTypes; } - public AddressInfo setRoutingTypes(EnumSet routingTypes) { + public AddressInfo setRoutingTypes(final EnumSet routingTypes) { this.routingTypes = routingTypes; - if (!routingTypes.isEmpty()) { - this.firstSeen = this.routingTypes.iterator().next(); + if (routingTypes != null && !routingTypes.isEmpty()) { + this.firstSeen = routingTypes.iterator().next(); + } else { + this.firstSeen = null; } return this; } - public AddressInfo addRoutingType(RoutingType routingType) { + public AddressInfo addRoutingType(final RoutingType routingType) { if (routingType != null) { - if (routingTypes == null) { + if (routingTypes == null || routingTypes.isEmpty()) { routingTypes = EnumSet.of(routingType); firstSeen = routingType; } else { - if (routingTypes.isEmpty()) { - firstSeen = routingType; - } routingTypes.add(routingType); } } @@ -127,7 +127,7 @@ public class AddressInfo { buff.append("Address [name=" + name); buff.append(", id=" + id); buff.append(", routingTypes={"); - for (RoutingType routingType : routingTypes) { + for (RoutingType routingType : getRoutingTypes()) { buff.append(routingType.toString() + ","); } // delete hanging comma