Skip to content

Commit

Permalink
GEODE-7525: Prevent NPE in MBeanProxyFactory (apache#4478)
Browse files Browse the repository at this point in the history
FederatingManager should not invoke MBeanProxyFactory.removeAllProxies
when monitoringRegion is null.
  • Loading branch information
kirklund authored Dec 17, 2019
1 parent 7187192 commit 9934558
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -334,18 +334,15 @@ void removeMemberArtifacts(DistributedMember member, boolean crashed) {

// If cache is closed all the regions would have been destroyed implicitly
if (!cache.isClosed()) {
try {
proxyFactory.removeAllProxies(member, monitoringRegion);
} catch (CancelException | RegionDestroyedException ignore) {
// ignored
}
try {
if (monitoringRegion != null) {
proxyFactory.removeAllProxies(member, monitoringRegion);
monitoringRegion.localDestroyRegion();
}
} catch (CancelException | RegionDestroyedException ignore) {
// ignored
}

try {
if (notificationRegion != null) {
notificationRegion.localDestroyRegion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.powermock.api.mockito.PowerMockito.when;

import java.net.InetAddress;
Expand Down Expand Up @@ -429,6 +430,23 @@ public void startManagerGetsNewExecutorServiceFromSupplier() {
verify(executorServiceSupplier).get();
}

@Test
public void removeMemberArtifactsDoesNotRemoveAllProxiesIfMonitoringRegionIsNull() {
InternalDistributedMember member = member();
when(repo.getEntryFromMonitoringRegionMap(eq(member)))
.thenReturn(null);
when(repo.getEntryFromNotifRegionMap(eq(member)))
.thenReturn(mock(Region.class));
when(system.getDistributedMember())
.thenReturn(member);
FederatingManager federatingManager = new FederatingManager(repo, system, service, cache,
statisticsFactory, statisticsClock, proxyFactory, messenger, executorService);

federatingManager.removeMemberArtifacts(member, false);

verifyZeroInteractions(proxyFactory);
}

private InternalDistributedMember member() {
return member(1, 1);
}
Expand Down

0 comments on commit 9934558

Please sign in to comment.