From 2cbf0c1774ed0529fc4910c768452902e346ff23 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Thu, 18 May 2023 12:02:48 +0200 Subject: [PATCH] Also add suppressed exception if unchecked exception occurs in finally If a method called in a finally block throws an exception we should add exceptions caught earlier to the exception we throw in the finally block not regarding if it's a checked or unchecked exception. Change-Id: I4c6be9a3a08482b07659ca31d6987ce719d81ca5 --- .../org/eclipse/jgit/internal/storage/pack/PackWriter.java | 5 +++++ .../src/org/eclipse/jgit/transport/FetchProcess.java | 2 +- .../src/org/eclipse/jgit/transport/WalkFetchConnection.java | 5 +++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java index 666e9d8cb..9508f3fe3 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java @@ -1723,6 +1723,11 @@ private void parallelDeltaSearch(ProgressMonitor monitor, } throw new IOException(JGitText .get().packingCancelledDuringObjectsWriting, e); + } catch (Throwable e) { + if (e1 != null) { + e.addSuppressed(e1); + } + throw e; } } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java index f02160e45..c510194ee 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java @@ -111,7 +111,7 @@ void execute(ProgressMonitor monitor, FetchResult result, for (PackLock lock : packLocks) { lock.unlock(); } - } catch (IOException e) { + } catch (Throwable e) { if (e1 != null) { e.addSuppressed(e1); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java index ed8f450c5..cc6c252fa 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java @@ -530,9 +530,10 @@ private boolean downloadPackedObject(final ProgressMonitor monitor, // are unusable and we shouldn't consult them again. // try { - if (pack.tmpIdx != null) + if (pack.tmpIdx != null) { FileUtils.delete(pack.tmpIdx); - } catch (IOException e) { + } + } catch (Throwable e) { if (e1 != null) { e.addSuppressed(e1); }