Skip to content

Commit

Permalink
GEODE-6779: added NPE checks (apache#3818)
Browse files Browse the repository at this point in the history
* GEODE-6779: added NPE checks

- DUnit tests show that beans can contain null values in any imaginable
place so we have to enhance the null value filtering
- Unit test enhanced to verify the checks

Authored-by: Joris Melchior <[email protected]>

* GEODE-6779: spotless fix

Authored-by: Joris Melchior <[email protected]>
  • Loading branch information
jmelchio authored and onichols-pivotal committed Jul 19, 2019
1 parent d338444 commit bc990cf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ private static boolean memberBeanDiskStoreExists(DistributedSystemMXBean dsMXBea
.filter(Objects::nonNull)
.map(DistributedSystemMXBean::listMemberDiskstore)
.filter(Objects::nonNull)
.flatMap(mds -> Stream.of(mds.get(memberName)))
.map(mds -> mds.get(memberName))
.filter(Objects::nonNull)
.flatMap(Stream::of)
.filter(Objects::nonNull)
.anyMatch(dsName -> dsName.equals(diskStore));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,34 @@ public void diskStoreBeanExistsMemberDiskStoreIsNull() throws Exception {
DiskStoreCommandsUtils.diskStoreBeanAndMemberBeanDiskStoreExists(distributedSystemMXBean,
memberName, diskStoreName)).isFalse();
}

@Test
public void diskStoreBeanExistsMemberDiskStoreContainsNullArray() throws Exception {
Map<String, String[]> memberDiskStore = new HashMap<>();
memberDiskStore.put(memberName, null);
ObjectName objectName = new ObjectName("");

DistributedSystemMXBean distributedSystemMXBean = Mockito.mock(DistributedSystemMXBean.class);
doReturn(memberDiskStore).when(distributedSystemMXBean).listMemberDiskstore();
doReturn(objectName).when(distributedSystemMXBean).fetchDiskStoreObjectName(any(), any());

assertThat(
DiskStoreCommandsUtils.diskStoreBeanAndMemberBeanDiskStoreExists(distributedSystemMXBean,
memberName, diskStoreName)).isFalse();
}

@Test
public void diskStoreBeanExistsMemberDiskStoreNamesHasNullValues() throws Exception {
Map<String, String[]> memberDiskStore = new HashMap<>();
memberDiskStore.put(memberName, new String[] {null, null});
ObjectName objectName = new ObjectName("");

DistributedSystemMXBean distributedSystemMXBean = Mockito.mock(DistributedSystemMXBean.class);
doReturn(memberDiskStore).when(distributedSystemMXBean).listMemberDiskstore();
doReturn(objectName).when(distributedSystemMXBean).fetchDiskStoreObjectName(any(), any());

assertThat(
DiskStoreCommandsUtils.diskStoreBeanAndMemberBeanDiskStoreExists(distributedSystemMXBean,
memberName, diskStoreName)).isFalse();
}
}

0 comments on commit bc990cf

Please sign in to comment.