]> source.dussan.org Git - jgit.git/commitdiff
[spotbugs] Fix potential NPE in FileRepository#convertToReftable 64/173364/3
authorMatthias Sohn <matthias.sohn@sap.com>
Thu, 3 Dec 2020 00:44:58 +0000 (01:44 +0100)
committerChristian Halstrick <christian.halstrick@sap.com>
Thu, 17 Dec 2020 16:18:11 +0000 (17:18 +0100)
File#listFiles can return null. Use Files#list which does not return
null and should be faster since it's returning directory entries lazily
while File#listFiles fetches them eagerly.

Change-Id: I3bfe2a52278244fc469143692c06b05d9af0d0d4
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java

index a2daef30d8aaef7fefa13e71dee91692c5e0c7c0..c8d3ffcd8f108cffcd923401f930c93432f9e0a6 100644 (file)
@@ -21,6 +21,7 @@ import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.nio.file.Files;
 import java.text.MessageFormat;
 import java.text.ParseException;
 import java.util.ArrayList;
@@ -727,7 +728,8 @@ public class FileRepository extends Repository {
                        throws IOException {
                File reftableDir = new File(getDirectory(), Constants.REFTABLE);
                File headFile = new File(getDirectory(), Constants.HEAD);
-               if (reftableDir.exists() && reftableDir.listFiles().length > 0) {
+               if (reftableDir.exists()
+                               && Files.list(reftableDir.toPath()).findAny().isPresent()) {
                        throw new IOException(JGitText.get().reftableDirExists);
                }