From: Matthias Sohn Date: Thu, 3 Dec 2020 01:04:36 +0000 (+0100) Subject: [spotbugs] Fix potential NPE in WorkingTreeIterator#isModified X-Git-Tag: v5.11.0.202102031030-m2~62 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=90b046e7abcfe56f072d0cf8733ffb576d2997af;p=jgit.git [spotbugs] Fix potential NPE in WorkingTreeIterator#isModified File#list can return null. Fix the potential NPE by using Files#list which is also faster since it retrieves directory entries lazily while File#list retrieves them eagerly. Change-Id: Idf4bda398861c647587e357326b8bc8b587a2584 Signed-off-by: Matthias Sohn --- diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java index 72278dc9c3..1a9d473a78 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java @@ -25,6 +25,7 @@ import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.CharacterCodingException; import java.nio.charset.CharsetEncoder; +import java.nio.file.Files; import java.nio.file.Path; import java.text.MessageFormat; import java.time.Instant; @@ -983,8 +984,9 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { return true; } else if (ObjectId.zeroId().compareTo(idBuffer, idOffset) == 0) { - return new File(repository.getWorkTree(), - entry.getPathString()).list().length > 0; + Path p = repository.getWorkTree().toPath() + .resolve(entry.getPathString()); + return Files.list(p).findAny().isPresent(); } return false; } else if (mode == FileMode.SYMLINK.getBits())