diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2020-12-03 01:44:58 +0100 |
---|---|---|
committer | Christian Halstrick <christian.halstrick@sap.com> | 2020-12-17 17:18:11 +0100 |
commit | a2bb540f2998689ae9c7f894ca5d74c6c55f9127 (patch) | |
tree | e0efabec6de1a15b009bf31f8eaf92a2b4ae17c6 /org.eclipse.jgit | |
parent | 15998622fabadf3931658d9cf359ed28c36fed23 (diff) | |
download | jgit-a2bb540f2998689ae9c7f894ca5d74c6c55f9127.tar.gz jgit-a2bb540f2998689ae9c7f894ca5d74c6c55f9127.zip |
[spotbugs] Fix potential NPE in FileRepository#convertToReftable
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>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java index a2daef30d8..c8d3ffcd8f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java @@ -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); } |