You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by mb...@apache.org on 2024/11/29 03:53:01 UTC
(asterixdb) 01/10: [NO ISSUE][HYR][MISC] += InvokeUtil.tryWithCleanups variant that passes exception to cleanups
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 813c15b3243d6a1f7d42a3ce5db7dee220038d33
Author: Michael Blow <mi...@couchbase.com>
AuthorDate: Mon Nov 25 16:16:32 2024 -0500
[NO ISSUE][HYR][MISC] += InvokeUtil.tryWithCleanups variant that passes exception to cleanups
Ext-ref: MB-64393
Change-Id: Iffecd13861ca430377e0f6a29a8b84cf8d33ca57
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/19127
Reviewed-by: Michael Blow <mb...@apache.org>
Tested-by: Michael Blow <mb...@apache.org>
---
.../org/apache/hyracks/api/util/InvokeUtil.java | 39 ++++++++++++++++++++++
1 file changed, 39 insertions(+)
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 ad5e91909b..e7970d31be 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
@@ -35,6 +35,7 @@ import org.apache.hyracks.util.InterruptibleAction;
import org.apache.hyracks.util.InterruptibleSupplier;
import org.apache.hyracks.util.Span;
import org.apache.hyracks.util.ThrowingAction;
+import org.apache.hyracks.util.ThrowingConsumer;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -251,6 +252,44 @@ public class InvokeUtil {
}
}
+ // catching Throwable, instanceofs, false-positive unreachable code
+ public static void tryWithCleanups(ThrowingAction action, ThrowingConsumer<Throwable>... cleanups)
+ throws Exception {
+ Throwable savedT = null;
+ boolean suppressedInterrupted = false;
+ try {
+ action.run();
+ } catch (Throwable t) {
+ savedT = t;
+ } finally {
+ for (ThrowingConsumer cleanup : cleanups) {
+ try {
+ cleanup.process(savedT);
+ } catch (Throwable t) {
+ if (savedT != null) {
+ savedT.addSuppressed(t);
+ suppressedInterrupted = suppressedInterrupted || t instanceof InterruptedException;
+ } else {
+ savedT = t;
+ }
+ }
+ }
+ }
+ if (savedT == null) {
+ return;
+ }
+ if (suppressedInterrupted) {
+ Thread.currentThread().interrupt();
+ }
+ if (savedT instanceof Error) {
+ throw (Error) savedT;
+ } else if (savedT instanceof Exception) {
+ throw (Exception) savedT;
+ } else {
+ throw HyracksDataException.create(savedT);
+ }
+ }
+
@SuppressWarnings({ "squid:S1181", "squid:S1193", "ConstantConditions" }) // catching Throwable, instanceofs
public static void tryIoWithCleanups(IOThrowingAction action, IOThrowingAction... cleanups) throws IOException {
Throwable savedT = null;