[spotbugs] Fix potential NPEs in FileReftableStackTest

File#listFiles can return null. Use Files#list instead to fix the
problem.

Change-Id: I74e0b49aa6dae370219507c64aa43be4d8aa7b82
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
Matthias Sohn 2020-12-04 01:26:23 +01:00 committed by Christian Halstrick
parent 90b046e7ab
commit cc7a1891ee
1 changed files with 12 additions and 7 deletions

View File

@ -18,7 +18,8 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@ -90,8 +91,9 @@ public void testCompaction(int N) throws Exception {
assertEquals(ObjectId.zeroId(), c.getRef().getObjectId());
}
List<String> files = Arrays.asList(reftableDir.listFiles()).stream()
.map(File::getName).collect(Collectors.toList());
List<String> files = Files.list(reftableDir.toPath())
.map(Path::getFileName).map(Path::toString)
.collect(Collectors.toList());
Collections.sort(files);
assertTrue(files.size() < 20);
@ -130,11 +132,14 @@ public void missingReftable() throws Exception {
});
assertTrue(ok);
List<File> files = Arrays.asList(reftableDir.listFiles());
List<Path> files = Files.list(reftableDir.toPath())
.collect(Collectors.toList());
for (int j = 0; j < files.size(); j++) {
File f = files.get(j);
if (f.getName().endsWith(".ref")) {
assertTrue(f.delete());
Path f = files.get(j);
Path fileName = f.getFileName();
if (fileName != null
&& fileName.toString().endsWith(".ref")) {
Files.delete(f);
break outer;
}
}