This is an automated email from the ASF dual-hosted git repository. mblow pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/asterixdb.git
commit 470bb657d3a1eb627e681644635d54467898decb Author: Michael Blow <[email protected]> AuthorDate: Fri Aug 30 06:42:51 2024 -0400 [NO ISSUE][HYR][MISC] += InvokeUtil.runWithCleanupsUnchecked Ext-ref: MB-63363 Change-Id: Ida57bd21c412fa935c7babaf0ae47e3ea05b4794 Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/18779 Reviewed-by: Michael Blow <[email protected]> Reviewed-by: Murtadha Hubail <[email protected]> Integration-Tests: Jenkins <[email protected]> Tested-by: Jenkins <[email protected]> --- .../org/apache/hyracks/api/util/InvokeUtil.java | 29 +++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/InvokeUtil.java b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/InvokeUtil.java index c50c6b5fc0..3ed17b138d 100644 --- a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/InvokeUtil.java +++ b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/InvokeUtil.java @@ -213,7 +213,8 @@ public class InvokeUtil { } } - @SuppressWarnings({ "squid:S1181", "squid:S1193", "ConstantConditions" }) // catching Throwable, instanceofs + @SuppressWarnings({ "squid:S1181", "squid:S1193", "ConstantConditions", "UnreachableCode" }) + // catching Throwable, instanceofs, false-positive unreachable code public static void tryWithCleanups(ThrowingAction action, ThrowingAction... cleanups) throws Exception { Throwable savedT = null; boolean suppressedInterrupted = false; @@ -287,6 +288,32 @@ public class InvokeUtil { } } + public static void tryWithCleanupsUnchecked(Runnable action, Runnable... cleanups) { + Throwable savedT = null; + try { + action.run(); + } catch (Throwable t) { + savedT = t; + } finally { + for (Runnable cleanup : cleanups) { + try { + cleanup.run(); + } catch (Throwable t) { + if (savedT != null) { + savedT.addSuppressed(t); + } else { + savedT = t; + } + } + } + } + if (savedT instanceof Error) { + throw (Error) savedT; + } else if (savedT != null) { + throw new UncheckedExecutionException(savedT); + } + } + /** * Runs the supplied action, after suspending any pending interruption. An error will be logged if * the action is itself interrupted.
