This is an automated email from the ASF dual-hosted git repository.

bschuchardt pushed a commit to branch feature/GEODE-7760
in repository https://gitbox.apache.org/repos/asf/geode.git

commit d76da5baa10e50fbfa0d2cc6e288d724e0a6878d
Author: Bruce Schuchardt <bschucha...@pivotal.io>
AuthorDate: Mon Feb 3 11:19:32 2020 -0800

    GEODE-7760: NPE in Locator during auto-reconnect
---
 .../internal/InternalLocatorIntegrationTest.java         | 13 +++++++++++++
 .../geode/distributed/internal/InternalLocator.java      | 16 ++++++++++------
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git 
a/geode-core/src/integrationTest/java/org/apache/geode/distributed/internal/InternalLocatorIntegrationTest.java
 
b/geode-core/src/integrationTest/java/org/apache/geode/distributed/internal/InternalLocatorIntegrationTest.java
index 3608488..6daab5f 100644
--- 
a/geode-core/src/integrationTest/java/org/apache/geode/distributed/internal/InternalLocatorIntegrationTest.java
+++ 
b/geode-core/src/integrationTest/java/org/apache/geode/distributed/internal/InternalLocatorIntegrationTest.java
@@ -99,6 +99,19 @@ public class InternalLocatorIntegrationTest {
   }
 
   @Test
+  public void restartingClusterConfigurationDoesNotThrowException() throws 
IOException {
+    internalLocator = InternalLocator.startLocator(port, logFile, logWriter,
+        securityLogWriter, bindAddress, true,
+        distributedSystemProperties, hostnameForClients, workingDirectory);
+    internalLocator.stop(true, true, false);
+    assertThat(InternalLocator.getLocator()).isNull();
+    // try starting a cluster configuration service when a reconnected locator 
doesn't exist
+    assertThatCode(() -> {
+      internalLocator.startClusterManagementService();
+    }).doesNotThrowAnyException();
+  }
+
+  @Test
   public void startedLocatorIsRunning() throws IOException {
     internalLocator = InternalLocator.startLocator(port, logFile, logWriter,
         securityLogWriter, bindAddress, true,
diff --git 
a/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java
 
b/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java
index b7475ad..0351c52 100644
--- 
a/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java
+++ 
b/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java
@@ -773,15 +773,19 @@ public class InternalLocator extends Locator implements 
ConnectListener, LogConf
     startClusterManagementService();
   }
 
-  private void startClusterManagementService() throws IOException {
+  @VisibleForTesting
+  void startClusterManagementService() throws IOException {
     startConfigurationPersistenceService();
 
-    if (internalCache == null) {
+    InternalCache myCache = this.internalCache;
+    InternalLocator currentLocator = InternalLocator.locator;
+
+    if (myCache == null || currentLocator == null) {
       return;
     }
 
-    clusterManagementService = new 
LocatorClusterManagementService(locator.internalCache,
-        locator.configurationPersistenceService);
+    clusterManagementService = new 
LocatorClusterManagementService(currentLocator.internalCache,
+        currentLocator.configurationPersistenceService);
 
     // start management rest service
     AgentUtil agentUtil = new AgentUtil(GemFireVersion.getGemFireVersion());
@@ -796,7 +800,7 @@ public class InternalLocator extends Locator implements 
ConnectListener, LogConf
 
     Map<String, Object> serviceAttributes = new HashMap<>();
     serviceAttributes.put(HttpService.SECURITY_SERVICE_SERVLET_CONTEXT_PARAM,
-        internalCache.getSecurityService());
+        myCache.getSecurityService());
     serviceAttributes.put(HttpService.CLUSTER_MANAGEMENT_SERVICE_CONTEXT_PARAM,
         clusterManagementService);
 
@@ -807,7 +811,7 @@ public class InternalLocator extends Locator implements 
ConnectListener, LogConf
     serviceAttributes.put(HttpService.AUTH_TOKEN_ENABLED_PARAM, 
managementAuthTokenEnabled);
 
     if (distributionConfig.getEnableManagementRestService()) {
-      internalCache.getOptionalService(HttpService.class).ifPresent(x -> {
+      myCache.getOptionalService(HttpService.class).ifPresent(x -> {
         try {
           logger.info("Geode Property {}=true Geode Management Rest Service is 
enabled.",
               ConfigurationProperties.ENABLE_MANAGEMENT_REST_SERVICE);

Reply via email to