Repository: activemq Updated Branches: refs/heads/trunk bbc039fce -> 60bdfc061
https://issues.apache.org/jira/browse/AMQ-5315 Fix for possible NPE during start with immediate bridge failure. Project: http://git-wip-us.apache.org/repos/asf/activemq/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/60bdfc06 Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/60bdfc06 Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/60bdfc06 Branch: refs/heads/trunk Commit: 60bdfc061cf3ced688a6b5aca9f00c4a3390312a Parents: bbc039f Author: Timothy Bish <[email protected]> Authored: Fri Aug 29 10:06:53 2014 -0400 Committer: Timothy Bish <[email protected]> Committed: Fri Aug 29 10:06:53 2014 -0400 ---------------------------------------------------------------------- .../network/DemandForwardingBridgeSupport.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq/blob/60bdfc06/activemq-broker/src/main/java/org/apache/activemq/network/DemandForwardingBridgeSupport.java ---------------------------------------------------------------------- diff --git a/activemq-broker/src/main/java/org/apache/activemq/network/DemandForwardingBridgeSupport.java b/activemq-broker/src/main/java/org/apache/activemq/network/DemandForwardingBridgeSupport.java index 2242d73..f61c5ac 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/network/DemandForwardingBridgeSupport.java +++ b/activemq-broker/src/main/java/org/apache/activemq/network/DemandForwardingBridgeSupport.java @@ -107,7 +107,7 @@ public abstract class DemandForwardingBridgeSupport implements NetworkBridge, Br protected static final String DURABLE_SUB_PREFIX = "NC-DS_"; protected final Transport localBroker; protected final Transport remoteBroker; - protected IdGenerator idGenerator; + protected IdGenerator idGenerator = new IdGenerator(); protected final LongSequenceGenerator consumerIdGenerator = new LongSequenceGenerator(); protected ConnectionInfo localConnectionInfo; protected ConnectionInfo remoteConnectionInfo; @@ -381,8 +381,6 @@ public abstract class DemandForwardingBridgeSupport implements NetworkBridge, Br remoteBrokerName = remoteBrokerInfo.getBrokerName(); if (configuration.isUseBrokerNamesAsIdSeed()) { idGenerator = new IdGenerator(brokerService.getBrokerName() + "->" + remoteBrokerName); - } else { - idGenerator = new IdGenerator(); } } catch (Throwable e) { serviceLocalException(e); @@ -433,10 +431,15 @@ public abstract class DemandForwardingBridgeSupport implements NetworkBridge, Br } private void startLocalBridge() throws Throwable { - if (localBridgeStarted.compareAndSet(false, true)) { + if (!bridgeFailed.get() && localBridgeStarted.compareAndSet(false, true)) { synchronized (this) { LOG.trace("{} starting local Bridge, localBroker={}", configuration.getBrokerName(), localBroker); if (!disposed.get()) { + + if (idGenerator == null) { + throw new IllegalStateException("Id Generator cannot be null"); + } + localConnectionInfo = new ConnectionInfo(); localConnectionInfo.setConnectionId(new ConnectionId(idGenerator.generateId())); localClientId = configuration.getName() + "_" + remoteBrokerName + "_inbound_" + configuration.getBrokerName(); @@ -518,7 +521,7 @@ public abstract class DemandForwardingBridgeSupport implements NetworkBridge, Br } protected void startRemoteBridge() throws Exception { - if (remoteBridgeStarted.compareAndSet(false, true)) { + if (!bridgeFailed.get() && remoteBridgeStarted.compareAndSet(false, true)) { LOG.trace("{} starting remote Bridge, remoteBroker={}", configuration.getBrokerName(), remoteBroker); synchronized (this) { if (!isCreatedByDuplex()) { @@ -810,8 +813,8 @@ public abstract class DemandForwardingBridgeSupport implements NetworkBridge, Br } else if (data.getClass() == RemoveSubscriptionInfo.class) { RemoveSubscriptionInfo info = ((RemoveSubscriptionInfo) data); SubscriptionInfo subscriptionInfo = new SubscriptionInfo(info.getClientId(), info.getSubscriptionName()); - for (Iterator i = subscriptionMapByLocalId.values().iterator(); i.hasNext(); ) { - DemandSubscription ds = (DemandSubscription) i.next(); + for (Iterator<DemandSubscription> i = subscriptionMapByLocalId.values().iterator(); i.hasNext(); ) { + DemandSubscription ds = i.next(); boolean removed = ds.getDurableRemoteSubs().remove(subscriptionInfo); if (removed) { if (ds.getDurableRemoteSubs().isEmpty()) {
