From b2af19db2d2651690458665e81e73151ef39fca7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Andr=C3=A9=20Pearce?= Date: Wed, 10 Oct 2018 07:56:56 +0100 Subject: [PATCH] NO-JIRA Fix NPE seen in test case logs --- .../artemis/core/server/impl/AddressInfo.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 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 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