diff --git a/engine/updategraph/src/main/java/io/deephaven/engine/updategraph/UpdateGraphAwareCompletableFuture.java b/engine/updategraph/src/main/java/io/deephaven/engine/updategraph/UpdateGraphAwareCompletableFuture.java index 7692c80a35b..1cf8d0cc36f 100644 --- a/engine/updategraph/src/main/java/io/deephaven/engine/updategraph/UpdateGraphAwareCompletableFuture.java +++ b/engine/updategraph/src/main/java/io/deephaven/engine/updategraph/UpdateGraphAwareCompletableFuture.java @@ -7,6 +7,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Objects; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; import java.util.concurrent.locks.Condition; @@ -57,6 +58,8 @@ public boolean isDone() { @Override public T get() throws InterruptedException, ExecutionException { + checkSharedLockState(); + if (resultSupplier != null) { return resultSupplier.get(); } @@ -70,6 +73,8 @@ public T get() throws InterruptedException, ExecutionException { @Override public T get(final long timeout, @NotNull final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { + checkSharedLockState(); + if (resultSupplier != null) { return resultSupplier.get(); } @@ -81,12 +86,6 @@ public T get(final long timeout, @NotNull final TimeUnit unit) private T getInternal(final long timeout, @Nullable final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { - // test lock conditions - if (updateGraph.sharedLock().isHeldByCurrentThread()) { - throw new UnsupportedOperationException( - "Cannot Future.get(...) while holding the " + updateGraph + " shared lock"); - } - final boolean holdingUpdateGraphLock = updateGraph.exclusiveLock().isHeldByCurrentThread(); if (holdingUpdateGraphLock) { if (updateGraphCondition == null) { @@ -111,6 +110,13 @@ private T getInternal(final long timeout, @Nullable final TimeUnit unit) return resultSupplier.get(); } + private void checkSharedLockState() { + if (updateGraph.sharedLock().isHeldByCurrentThread()) { + throw new UnsupportedOperationException( + "Cannot Future.get(...) while holding the " + updateGraph + " shared lock"); + } + } + private void waitForResult(final Condition condition, final long timeout, @Nullable final TimeUnit unit) throws InterruptedException, TimeoutException { if (unit == null) { @@ -138,9 +144,7 @@ public boolean complete(T value) { } public boolean completeExceptionally(Throwable ex) { - if (ex == null) { - throw new NullPointerException(); - } + Objects.requireNonNull(ex); return trySignalCompletion(() -> { throw new ExecutionException(ex); }); diff --git a/java-client/barrage/src/main/java/io/deephaven/client/impl/BarrageSubscriptionImpl.java b/java-client/barrage/src/main/java/io/deephaven/client/impl/BarrageSubscriptionImpl.java index 653a2c367f7..5d1a0006e43 100644 --- a/java-client/barrage/src/main/java/io/deephaven/client/impl/BarrageSubscriptionImpl.java +++ b/java-client/barrage/src/main/java/io/deephaven/client/impl/BarrageSubscriptionImpl.java @@ -250,8 +250,9 @@ private void onFutureComplete() { protected void destroy() { super.destroy(); cancel("no longer live"); - if (future != null) { - future.completeExceptionally(new RequestCancelledException("Barrage subscription is no longer live")); + final FutureAdapter localFuture = future; + if (localFuture != null) { + localFuture.completeExceptionally(new RequestCancelledException("Barrage subscription is no longer live")); } } diff --git a/server/src/main/java/io/deephaven/server/arrow/ArrowFlightUtil.java b/server/src/main/java/io/deephaven/server/arrow/ArrowFlightUtil.java index 789581ff3c0..c2351dfeae2 100644 --- a/server/src/main/java/io/deephaven/server/arrow/ArrowFlightUtil.java +++ b/server/src/main/java/io/deephaven/server/arrow/ArrowFlightUtil.java @@ -658,6 +658,12 @@ private synchronized void onExportResolved(final SessionState.ExportObject