From 28e5a7e52e92162111f341cfc252ae46e5c4cbfe Mon Sep 17 00:00:00 2001 From: franz1981 Date: Thu, 24 Sep 2020 01:36:01 +0200 Subject: [PATCH] ARTEMIS-2912 Handle NPE due to uninitialized members (cherry picked from commit 69fa4f3e93675dbe6458de8f4c58cce56bea64c5) downstream: ENTMQBR-4194 --- .../core/server/impl/ActiveMQServerImpl.java | 41 ++++++++++++++----- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java index 2861553762..c855b7ec43 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java @@ -1081,17 +1081,24 @@ void stop(boolean failoverOnServerShutdown, final boolean criticalIOError, boole state = SERVER_STATE.STOPPING; if (criticalIOError) { - // notifications trigger disk IO so we don't want to send any on a critical IO error - managementService.enableNotifications(false); + final ManagementService managementService = this.managementService; + if (managementService != null) { + // notifications trigger disk IO so we don't want to send any on a critical IO error + managementService.enableNotifications(false); + } } + final FileStoreMonitor fileStoreMonitor = this.fileStoreMonitor; if (fileStoreMonitor != null) { fileStoreMonitor.stop(); - fileStoreMonitor = null; + this.fileStoreMonitor = null; } if (failoverOnServerShutdown) { - activation.sendLiveIsStopping(); + final Activation activation = this.activation; + if (activation != null) { + activation.sendLiveIsStopping(); + } } stopComponent(connectorsService); @@ -1105,6 +1112,7 @@ void stop(boolean failoverOnServerShutdown, final boolean criticalIOError, boole stopComponent(federationManager); stopComponent(clusterManager); + final RemotingService remotingService = this.remotingService; if (remotingService != null) { remotingService.pauseAcceptors(); } @@ -1126,7 +1134,10 @@ void stop(boolean failoverOnServerShutdown, final boolean criticalIOError, boole freezeConnections(); } - activation.postConnectionFreeze(); + final Activation activation = this.activation; + if (activation != null) { + activation.postConnectionFreeze(); + } closeAllServerSessions(criticalIOError); @@ -1139,6 +1150,7 @@ void stop(boolean failoverOnServerShutdown, final boolean criticalIOError, boole // // ************************************************************************************************************* + final StorageManager storageManager = this.storageManager; if (storageManager != null) storageManager.clearContext(); @@ -1147,10 +1159,12 @@ void stop(boolean failoverOnServerShutdown, final boolean criticalIOError, boole stopComponent(backupManager); - try { - activation.preStorageClose(); - } catch (Throwable t) { - ActiveMQServerLogger.LOGGER.errorStoppingComponent(t, activation.getClass().getName()); + if (activation != null) { + try { + activation.preStorageClose(); + } catch (Throwable t) { + ActiveMQServerLogger.LOGGER.errorStoppingComponent(t, activation.getClass().getName()); + } } stopComponent(pagingManager); @@ -1164,6 +1178,7 @@ void stop(boolean failoverOnServerShutdown, final boolean criticalIOError, boole // We stop remotingService before otherwise we may lock the system in case of a critical IO // error shutdown + final RemotingService remotingService = this.remotingService; if (remotingService != null) try { remotingService.stop(criticalIOError); @@ -1172,6 +1187,7 @@ void stop(boolean failoverOnServerShutdown, final boolean criticalIOError, boole } // Stop the management service after the remoting service to ensure all acceptors are deregistered with JMX + final ManagementService managementService = this.managementService; if (managementService != null) try { managementService.unregisterServer(); @@ -1224,7 +1240,7 @@ void stop(boolean failoverOnServerShutdown, final boolean criticalIOError, boole messagingServerControl = null; memoryManager = null; backupManager = null; - storageManager = null; + this.storageManager = null; sessions.clear(); @@ -1321,7 +1337,10 @@ public boolean checkLiveIsNotColocated(String nodeId) { * {@link #stop(boolean, boolean, boolean)}. */ private void freezeConnections() { - activation.freezeConnections(remotingService); + Activation activation = this.activation; + if (activation != null) { + activation.freezeConnections(remotingService); + } // after disconnecting all the clients close all the server sessions so any messages in delivery will be cancelled back to the queue for (ServerSession serverSession : sessions.values()) {