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 @Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
String name = file.getFileName().toString(); Path fileName = file.getFileName();
if (!attrs.isDirectory() && badName.test(name)) { if (fileName != null) {
bad.add(name); String name = fileName.toString();
if (!attrs.isDirectory() && badName.test(name)) {
bad.add(name);
}
} }
return FileVisitResult.CONTINUE; return FileVisitResult.CONTINUE;
} }

Loading…
Cancel
Save