Browse Source

[infer] Fix potential NPE in CloneCommand

Change-Id: Ie7eeba3ae719ff207c7535d535a9e0bd6c9e99e6
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-4.7
Matthias Sohn 8 years ago
parent
commit
423a583fcc
  1. 24
      org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java

24
org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java

@ -151,23 +151,35 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
}
}
private static boolean isNonEmptyDirectory(File dir) {
if (dir != null && dir.exists()) {
File[] files = dir.listFiles();
return files != null && files.length != 0;
}
return false;
}
private Repository init(URIish u) throws GitAPIException {
InitCommand command = Git.init();
command.setBare(bare);
if (directory == null && gitDir == null)
if (directory == null && gitDir == null) {
directory = new File(u.getHumanishName(), Constants.DOT_GIT);
}
validateDirs(directory, gitDir, bare);
if (directory != null && directory.exists()
&& directory.listFiles().length != 0)
if (isNonEmptyDirectory(directory)) {
throw new JGitInternalException(MessageFormat.format(
JGitText.get().cloneNonEmptyDirectory, directory.getName()));
if (gitDir != null && gitDir.exists() && gitDir.listFiles().length != 0)
}
if (isNonEmptyDirectory(gitDir)) {
throw new JGitInternalException(MessageFormat.format(
JGitText.get().cloneNonEmptyDirectory, gitDir.getName()));
if (directory != null)
}
if (directory != null) {
command.setDirectory(directory);
if (gitDir != null)
}
if (gitDir != null) {
command.setGitDir(gitDir);
}
return command.call().getRepository();
}

Loading…
Cancel
Save