This is an automated email from the ASF dual-hosted git repository. gaohoward pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git
The following commit(s) were added to refs/heads/master by this push: new 55732d4 NO-JIRA Fix Possible NPE in connectToNodeInReplicatedCluster new 65d01a4 This closes #2509 55732d4 is described below commit 55732d401f14ea8e7c23f61b842821f4be2c3b4e Author: Michael André Pearce <michael.andre.pea...@me.com> AuthorDate: Fri Jan 18 23:09:53 2019 +0000 NO-JIRA Fix Possible NPE in connectToNodeInReplicatedCluster Variable possibleLive may be null, as signified by trace log above, also dedupe code. --- .../server/impl/SharedNothingBackupActivation.java | 35 ++++++++++++---------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedNothingBackupActivation.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedNothingBackupActivation.java index 4c360f0..587b8f0 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedNothingBackupActivation.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/SharedNothingBackupActivation.java @@ -213,22 +213,13 @@ public final class SharedNothingBackupActivation extends Activation { activeMQServer.getNodeManager().setNodeID(nodeID); } - try { - if (logger.isTraceEnabled()) { - logger.trace("Calling clusterController.connectToNodeInReplicatedCluster(" + possibleLive != null ? possibleLive.getA() : null + ")"); - } - clusterControl = clusterController.connectToNodeInReplicatedCluster(possibleLive.getA()); - } catch (Exception e) { - logger.debug(e.getMessage(), e); - if (possibleLive != null && possibleLive.getB() != null) { - try { - clusterControl = clusterController.connectToNodeInReplicatedCluster(possibleLive.getB()); - } catch (Exception e1) { - clusterControl = null; - } - } else { - clusterControl = null; + if (possibleLive != null) { + clusterControl = tryConnectToNodeInReplicatedCluster(clusterController, possibleLive.getA()); + if (clusterControl == null) { + clusterControl = tryConnectToNodeInReplicatedCluster(clusterController, possibleLive.getB()); } + } else { + clusterControl = null; } if (clusterControl == null) { @@ -367,6 +358,20 @@ public final class SharedNothingBackupActivation extends Activation { } } + private static ClusterControl tryConnectToNodeInReplicatedCluster(ClusterController clusterController, TransportConfiguration tc) { + try { + if (logger.isTraceEnabled()) { + logger.trace("Calling clusterController.connectToNodeInReplicatedCluster(" + tc + ")"); + } + if (tc != null) { + return clusterController.connectToNodeInReplicatedCluster(tc); + } + } catch (Exception e) { + logger.debug(e.getMessage(), e); + } + return null; + } + @Override public void close(final boolean permanently, boolean restarting) throws Exception { synchronized (this) {