From 7f3beb95e522a8f43e8b167b6a33d53d24c2d58a Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 26 Feb 2009 11:13:13 -0800 Subject: [PATCH] Catch any unexpected exceptions while closing a replication If the replication only partially initialized and then threw an exception, we may find that the underlying JSch connection is only partially initialized. Calling tn.close() from our finally block may throw a NullPointerException from within JSch, as JSch tries to cleanup uninitialized resources. By wrapping our close call in a try/catch we can ensure that any close failure is logged and then ignored, so that if the close was execting becaues an exception was thrown that the original exception can propagate to our exception handle and also be logged. Signed-off-by: Shawn O. Pearce --- src/main/java/com/google/gerrit/git/PushQueue.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/google/gerrit/git/PushQueue.java b/src/main/java/com/google/gerrit/git/PushQueue.java index cd6b733ebc..d9cc77c91d 100644 --- a/src/main/java/com/google/gerrit/git/PushQueue.java +++ b/src/main/java/com/google/gerrit/git/PushQueue.java @@ -158,7 +158,11 @@ public class PushQueue { log.error("Cannot replicate to " + op.uri, e); return; } finally { - tn.close(); + try { + tn.close(); + } catch (Throwable e2){ + log.warn("Unexpected error while closing " + op.uri, e2); + } } for (final RemoteRefUpdate u : res.getRemoteUpdates()) {