[findBugs] Prevent potential NPE in CloneCommand.init()
File.listFiles() returns null if the File is not a directory, improve validation of directory and gitDir to fix this. Change-Id: I763d08835faf96a0beb8e706992df0908526bd2c Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
parent
0269f07401
commit
6569a876a3
|
@ -314,6 +314,8 @@ indexFileIsTooLargeForJgit=Index file is too large for jgit
|
|||
indexSignatureIsInvalid=Index signature is invalid: {0}
|
||||
indexWriteException=Modified index could not be written
|
||||
initFailedBareRepoDifferentDirs=When initializing a bare repo with directory {0} and separate git-dir {1} specified both folders must point to the same location
|
||||
initFailedDirIsNoDirectory=Cannot set directory to ''{0}'' which is not a directory
|
||||
initFailedGitDirIsNoDirectory=Cannot set git-dir to ''{0}'' which is not a directory
|
||||
initFailedNonBareRepoSameDirs=When initializing a non-bare repo with directory {0} and separate git-dir {1} specified both folders should not point to the same location
|
||||
inMemoryBufferLimitExceeded=In-memory buffer limit exceeded
|
||||
inputDidntMatchLength=Input did not match supplied length. {0} bytes are missing.
|
||||
|
|
|
@ -155,6 +155,7 @@ private Repository init(URIish u) throws GitAPIException {
|
|||
command.setBare(bare);
|
||||
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)
|
||||
throw new JGitInternalException(MessageFormat.format(
|
||||
|
@ -511,6 +512,15 @@ public CloneCommand setNoCheckout(boolean noCheckout) {
|
|||
private static void validateDirs(File directory, File gitDir, boolean bare)
|
||||
throws IllegalStateException {
|
||||
if (directory != null) {
|
||||
if (directory.exists() && !directory.isDirectory()) {
|
||||
throw new IllegalStateException(MessageFormat.format(
|
||||
JGitText.get().initFailedDirIsNoDirectory, directory));
|
||||
}
|
||||
if (gitDir != null && gitDir.exists() && !gitDir.isDirectory()) {
|
||||
throw new IllegalStateException(MessageFormat.format(
|
||||
JGitText.get().initFailedGitDirIsNoDirectory,
|
||||
gitDir));
|
||||
}
|
||||
if (bare) {
|
||||
if (gitDir != null && !gitDir.equals(directory))
|
||||
throw new IllegalStateException(MessageFormat.format(
|
||||
|
|
|
@ -373,6 +373,8 @@ public static JGitText get() {
|
|||
/***/ public String indexSignatureIsInvalid;
|
||||
/***/ public String indexWriteException;
|
||||
/***/ public String initFailedBareRepoDifferentDirs;
|
||||
/***/ public String initFailedDirIsNoDirectory;
|
||||
/***/ public String initFailedGitDirIsNoDirectory;
|
||||
/***/ public String initFailedNonBareRepoSameDirs;
|
||||
/***/ public String inMemoryBufferLimitExceeded;
|
||||
/***/ public String inputDidntMatchLength;
|
||||
|
|
Loading…
Reference in New Issue