>From Michael Blow <[email protected]>:
Michael Blow has uploaded this change for review. (
https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/19127 )
Change subject: [NO ISSUE][HYR][MISC] += InvokeUtil.tryWithCleanups variant
that passes exception to cleanups
......................................................................
[NO ISSUE][HYR][MISC] += InvokeUtil.tryWithCleanups variant that passes
exception to cleanups
Change-Id: Iffecd13861ca430377e0f6a29a8b84cf8d33ca57
---
M
hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/InvokeUtil.java
1 file changed, 48 insertions(+), 0 deletions(-)
git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb
refs/changes/27/19127/1
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 ad5e919..e7970d3 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.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 @@
}
}
+ // 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;
--
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/19127
To unsubscribe, or for help writing mail filters, visit
https://asterix-gerrit.ics.uci.edu/settings
Gerrit-Project: asterixdb
Gerrit-Branch: goldfish
Gerrit-Change-Id: Iffecd13861ca430377e0f6a29a8b84cf8d33ca57
Gerrit-Change-Number: 19127
Gerrit-PatchSet: 1
Gerrit-Owner: Michael Blow <[email protected]>
Gerrit-MessageType: newchange