Ignore IllegalStateException if JVM is already shutting down
Trying to register/unregister a shutdown hook when the JVM is already in shutdown throws an IllegalStateException. Ignore this exception since we can't do anything about it. Bug: 575367 Change-Id: Ic967c16c7f566c84778795315ab369e76668b364
This commit is contained in:
parent
c697f02e12
commit
6817b7e3b4
|
@ -219,8 +219,12 @@ public final void execute(String[] args) throws Exception {
|
|||
case APACHE: {
|
||||
SshdSessionFactory factory = new SshdSessionFactory(
|
||||
new JGitKeyCache(), new DefaultProxyDataFactory());
|
||||
try {
|
||||
Runtime.getRuntime()
|
||||
.addShutdownHook(new Thread(factory::close));
|
||||
} catch (IllegalStateException e) {
|
||||
// ignore - the VM is already shutting down
|
||||
}
|
||||
SshSessionFactory.setInstance(factory);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -173,7 +173,11 @@ public Git call() throws GitAPIException, InvalidRemoteException,
|
|||
Repository repository = init();
|
||||
FetchResult fetchResult = null;
|
||||
Thread cleanupHook = new Thread(() -> cleanup());
|
||||
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 Git call() throws GitAPIException, InvalidRemoteException,
|
|||
cleanup();
|
||||
throw e;
|
||||
} finally {
|
||||
try {
|
||||
Runtime.getRuntime().removeShutdownHook(cleanupHook);
|
||||
} catch (IllegalStateException e) {
|
||||
// ignore - the VM is already shutting down
|
||||
}
|
||||
}
|
||||
if (!noCheckout) {
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue