Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8507a2a8 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Correctly handle AndroidFuture#cancel"

parents 1797318b 78e6b493
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.Preconditions;
import com.android.internal.util.function.pooled.PooledLambda;

import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ExecutionException;
@@ -129,7 +130,23 @@ public class AndroidFuture<T> extends CompletableFuture<T> implements Parcelable
        if (changed) {
            onCompleted(null, ex);
        }
        return super.completeExceptionally(ex);
        return changed;
    }

    @Override
    public boolean cancel(boolean mayInterruptIfRunning) {
        boolean changed = super.cancel(mayInterruptIfRunning);
        if (changed) {
            try {
                get();
                throw new IllegalStateException("Expected CancellationException");
            } catch (CancellationException ex) {
                onCompleted(null, ex);
            } catch (Throwable e) {
                throw new IllegalStateException("Expected CancellationException", e);
            }
        }
        return changed;
    }

    @CallSuper