diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2020-12-04 01:26:23 +0100 |
---|---|---|
committer | Christian Halstrick <christian.halstrick@sap.com> | 2020-12-17 18:42:00 +0100 |
commit | cc7a1891ee383af61d0982fd8b8313ba68987b3c (patch) | |
tree | 3b880fe591630c901072354a5c52f740f57831ca /org.eclipse.jgit.test/tst | |
parent | 90b046e7abcfe56f072d0cf8733ffb576d2997af (diff) | |
download | jgit-cc7a1891ee383af61d0982fd8b8313ba68987b3c.tar.gz jgit-cc7a1891ee383af61d0982fd8b8313ba68987b3c.zip |
[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>
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableStackTest.java | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableStackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableStackTest.java index 72bff16831..6c74f0079a 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableStackTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableStackTest.java @@ -18,7 +18,8 @@ import static org.junit.Assert.assertTrue; 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 class FileReftableStackTest { 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 class FileReftableStackTest { }); 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; } } |