]> source.dussan.org Git - jgit.git/commitdiff
PackInserterTest: Prevent potential NPE dereferencing Path.getFileName() 49/113049/1
authorDavid Pursehouse <david.pursehouse@gmail.com>
Fri, 8 Dec 2017 08:21:35 +0000 (17:21 +0900)
committerDavid Pursehouse <david.pursehouse@gmail.com>
Fri, 8 Dec 2017 08:21:52 +0000 (17:21 +0900)
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>
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackInserterTest.java

index 17f04c8548b81e8fc799c9ec20e8ebb9db5f4c82..814e148db6a60ac5a17172d0508d87a0708f2f53 100644 (file)
@@ -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;
                }