aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java8
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java12
2 files changed, 16 insertions, 4 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java
index f70e72d434..600200d71d 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java
@@ -219,8 +219,12 @@ public abstract class TextBuiltin {
case APACHE: {
SshdSessionFactory factory = new SshdSessionFactory(
new JGitKeyCache(), new DefaultProxyDataFactory());
- Runtime.getRuntime()
- .addShutdownHook(new Thread(factory::close));
+ try {
+ Runtime.getRuntime()
+ .addShutdownHook(new Thread(factory::close));
+ } catch (IllegalStateException e) {
+ // ignore - the VM is already shutting down
+ }
SshSessionFactory.setInstance(factory);
break;
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java
index cf7bc1f263..3aa711455b 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java
@@ -173,7 +173,11 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
Repository repository = init();
FetchResult fetchResult = null;
Thread cleanupHook = new Thread(() -> cleanup());
- Runtime.getRuntime().addShutdownHook(cleanupHook);
+ try {
+ Runtime.getRuntime().addShutdownHook(cleanupHook);
+ } catch (IllegalStateException e) {
+ // ignore - the VM is already shutting down
+ }
try {
fetchResult = fetch(repository, u);
} catch (IOException ioe) {
@@ -197,7 +201,11 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
cleanup();
throw e;
} finally {
- Runtime.getRuntime().removeShutdownHook(cleanupHook);
+ try {
+ Runtime.getRuntime().removeShutdownHook(cleanupHook);
+ } catch (IllegalStateException e) {
+ // ignore - the VM is already shutting down
+ }
}
if (!noCheckout) {
try {