Browse Source

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>
stable-4.10
David Pursehouse 7 years ago
parent
commit
c861c0e2ee
  1. 9
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackInserterTest.java

9
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;
}

Loading…
Cancel
Save