[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 <mblow@apache.org>
Reviewed-by: Murtadha Hubail <mhubail@apache.org>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
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 c50c6b5..3ed17b1 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 @@
}
}
- @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 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.