summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Halstrick <christian.halstrick@sap.com>2015-07-10 13:01:10 +0200
committerChristian Halstrick <christian.halstrick@sap.com>2015-08-16 22:20:06 +0200
commitd0d637342b5ac4381eee2b28ed71d2faa3156093 (patch)
treeacb9866d7a1153a7f0caa1ffd249638de8eab637
parentf9bd6c1239b9e66bfd74e5a2462621a5f5fa641c (diff)
downloadjgit-d0d637342b5ac4381eee2b28ed71d2faa3156093.tar.gz
jgit-d0d637342b5ac4381eee2b28ed71d2faa3156093.zip
Change FS not to throw NPE when facing InMemory databases
The FS class and the subclasses FS_POSIX assumed in the findHook() method that every repository has a valid gitDir. But in tests when using in-memory-repositories this is not true and this method was generating NPEs. Change the method to return null if no repository directory can be determined. Change-Id: I38a4d36dc6452b5dacae3d0dbf562b569ca3c19b
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java5
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java3
2 files changed, 7 insertions, 1 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java
index 47c747e80d..c1535fa1fb 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java
@@ -866,7 +866,10 @@ public abstract class FS {
* @since 4.0
*/
public File findHook(Repository repository, final String hookName) {
- final File hookFile = new File(new File(repository.getDirectory(),
+ File gitDir = repository.getDirectory();
+ if (gitDir == null)
+ return null;
+ final File hookFile = new File(new File(gitDir,
Constants.HOOKS), hookName);
return hookFile.isFile() ? hookFile : null;
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java
index b07f8594db..80c7290073 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java
@@ -335,6 +335,9 @@ public class FS_POSIX extends FS {
@Override
public File findHook(Repository repository, String hookName) {
final File gitdir = repository.getDirectory();
+ if (gitdir == null) {
+ return null;
+ }
final Path hookPath = gitdir.toPath().resolve(Constants.HOOKS)
.resolve(hookName);
if (Files.isExecutable(hookPath))