NO-JIRA Fix NPE seen in test case logs
Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/b2af19db Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/b2af19db Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/b2af19db Branch: refs/heads/master Commit: b2af19db2d2651690458665e81e73151ef39fca7 Parents: 0d665b5 Author: Michael André Pearce <[email protected]> Authored: Wed Oct 10 07:56:56 2018 +0100 Committer: Michael Andre Pearce <[email protected]> Committed: Wed Oct 10 17:17:31 2018 +0100 ---------------------------------------------------------------------- .../artemis/core/server/impl/AddressInfo.java | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b2af19db/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AddressInfo.java ---------------------------------------------------------------------- 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 0cf9452..db2c67a 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<RoutingType> EMPTY_ROUTING_TYPES = EnumSet.noneOf(RoutingType.class); private EnumSet<RoutingType> routingTypes; private RoutingType firstSeen; @@ -91,26 +92,25 @@ public class AddressInfo { } public EnumSet<RoutingType> getRoutingTypes() { - return routingTypes; + return routingTypes == null ? EMPTY_ROUTING_TYPES : routingTypes; } - public AddressInfo setRoutingTypes(EnumSet<RoutingType> routingTypes) { + public AddressInfo setRoutingTypes(final EnumSet<RoutingType> 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
