>From Michael Blow <[email protected]>: Michael Blow has submitted this change. ( 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 Ext-ref: MB-64393 Change-Id: Iffecd13861ca430377e0f6a29a8b84cf8d33ca57 Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/19127 Reviewed-by: Michael Blow <[email protected]> Tested-by: Michael Blow <[email protected]> --- M hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/InvokeUtil.java 1 file changed, 52 insertions(+), 0 deletions(-) Approvals: Michael Blow: Looks good to me, approved; Verified 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: 3 Gerrit-Owner: Michael Blow <[email protected]> Gerrit-Reviewer: Ali Alsuliman <[email protected]> Gerrit-Reviewer: Anon. E. Moose #1000171 Gerrit-Reviewer: Jenkins <[email protected]> Gerrit-Reviewer: Michael Blow <[email protected]> Gerrit-MessageType: merged
