]> source.dussan.org Git - jgit.git/commitdiff
[spotbugs] Fix potential NPE in WorkingTreeIterator#isModified 67/173367/4
authorMatthias Sohn <matthias.sohn@sap.com>
Thu, 3 Dec 2020 01:04:36 +0000 (02:04 +0100)
committerChristian Halstrick <christian.halstrick@sap.com>
Thu, 17 Dec 2020 17:42:00 +0000 (18:42 +0100)
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 <matthias.sohn@sap.com>
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java

index 72278dc9c351fe044b10a11612bc39e88af649af..1a9d473a788d309d019f78b538730ccd4b044411 100644 (file)
@@ -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())