summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2017-12-08 17:21:35 +0900
committerDavid Pursehouse <david.pursehouse@gmail.com>2017-12-08 17:21:52 +0900
commitc861c0e2ee3eb919e8d43f7244e891084ac58513 (patch)
tree6f52c7802f7c4fc699435346178efbde64a98a1c /org.eclipse.jgit.test
parent0e5b9f8a39a955a58f39466264afed372b27aaa2 (diff)
downloadjgit-c861c0e2ee3eb919e8d43f7244e891084ac58513.tar.gz
jgit-c861c0e2ee3eb919e8d43f7244e891084ac58513.zip
PackInserterTest: Prevent potential NPE dereferencing Path.getFileName()
Path.getFileName() may return null if the path has zero elements. Enclose the dereference in a null-check. Change-Id: I7ea3d3f07edc13a80b593d28e8fd512a4e1ed56b Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackInserterTest.java9
1 files changed, 6 insertions, 3 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackInserterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackInserterTest.java
index 17f04c8548..814e148db6 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackInserterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackInserterTest.java
@@ -529,9 +529,12 @@ public class PackInserterTest extends RepositoryTestCase {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
- String name = file.getFileName().toString();
- if (!attrs.isDirectory() && badName.test(name)) {
- bad.add(name);
+ Path fileName = file.getFileName();
+ if (fileName != null) {
+ String name = fileName.toString();
+ if (!attrs.isDirectory() && badName.test(name)) {
+ bad.add(name);
+ }
}
return FileVisitResult.CONTINUE;
}