Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 683725351
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Oct 8, 2024
1 parent 01e6a55 commit 49776fd
Show file tree
Hide file tree
Showing 18 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,7 @@ protected boolean setException(Throwable throwable) {
* @since 19.0
*/
@CanIgnoreReturnValue
@SuppressWarnings("Interruption") // We are propagating an interrupt from a caller.
protected boolean setFuture(ListenableFuture<? extends V> future) {
checkNotNull(future);
@RetainedLocalRef Object localValue = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ private static final class FutureAsCancellable implements Cancellable {
}

@Override
@SuppressWarnings("Interruption") // We are propagating an interrupt from a caller.
public void cancel(boolean mayInterruptIfRunning) {
delegate.cancel(mayInterruptIfRunning);
}
Expand Down Expand Up @@ -627,6 +628,7 @@ private static final class SupplantableFuture implements Cancellable {
}

@Override
@SuppressWarnings("Interruption") // We are propagating an interrupt from a caller.
public void cancel(boolean mayInterruptIfRunning) {
/*
* Lock to ensure that a task cannot be rescheduled while a cancel is ongoing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ abstract class AggregateFuture<InputT extends @Nullable Object, OutputT extends
}

@Override
@SuppressWarnings("Interruption") // We are propagating an interrupt from a caller.
protected final void afterDone() {
super.afterDone();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,7 @@ public void run() {
* completed normally; {@code true} otherwise
*/
@CanIgnoreReturnValue
@SuppressWarnings("Interruption") // We are propagating an interrupt from a caller.
public boolean cancel(boolean mayInterruptIfRunning) {
logger.get().log(FINER, "cancelling {0}", this);
boolean cancelled = future.cancel(mayInterruptIfRunning);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,7 @@ private void recordInputCompletion(
delegateIndex = delegates.size();
}

@SuppressWarnings("Interruption") // We are propagating an interrupt from a caller.
private void recordCompletion() {
if (incompleteOutputCount.decrementAndGet() == 0 && wasCancelled) {
for (ListenableFuture<? extends T> toCancel : inputFutures) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public final void run() {
}
}

@SuppressWarnings("Interruption") // We are restoring an interrupt on this thread.
private void waitForInterrupt(Thread currentThread) {
/*
* If someone called cancel(true), it is possible that the interrupted bit hasn't been set yet.
Expand Down Expand Up @@ -189,6 +190,7 @@ private void waitForInterrupt(Thread currentThread) {
* Interrupts the running task. Because this internally calls {@link Thread#interrupt()} which can
* in turn invoke arbitrary code it is not safe to call while holding a lock.
*/
@SuppressWarnings("Interruption") // We are implementing a user-requested interrupt.
final void interruptTask() {
// Since the Thread is replaced by DONE before run() invokes listeners or returns, if we succeed
// in this CAS, there's no risk of interrupting the wrong thread or interrupting a thread that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ protected String pendingToString() {
@SuppressWarnings({
"GoodTime", // should accept a java.time.Duration
"CatchingUnchecked", // sneaky checked exception
"Interruption", // We copy AbstractExecutorService.invokeAny. Maybe we shouldn't: b/227335009.
})
@J2ktIncompatible
@GwtIncompatible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
@J2ktIncompatible
@GwtIncompatible
@ElementTypesAreNonnullByDefault
// TODO: b/227335009 - Maybe change interruption behavior, but it requires thought.
@SuppressWarnings("Interruption")
public final class SimpleTimeLimiter implements TimeLimiter {

private final ExecutorService executor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ private static final class Fire<V extends @Nullable Object> implements Runnable
}

@Override
// TODO: b/227335009 - Maybe change interruption behavior, but it requires thought.
@SuppressWarnings("Interruption")
public void run() {
// If either of these reads return null then we must be after a successful cancel or another
// call to this method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,7 @@ protected boolean setException(Throwable throwable) {
* @since 19.0
*/
@CanIgnoreReturnValue
@SuppressWarnings("Interruption") // We are propagating an interrupt from a caller.
protected boolean setFuture(ListenableFuture<? extends V> future) {
checkNotNull(future);
@RetainedLocalRef Object localValue = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ private static final class FutureAsCancellable implements Cancellable {
}

@Override
@SuppressWarnings("Interruption") // We are propagating an interrupt from a caller.
public void cancel(boolean mayInterruptIfRunning) {
delegate.cancel(mayInterruptIfRunning);
}
Expand Down Expand Up @@ -669,6 +670,7 @@ private static final class SupplantableFuture implements Cancellable {
}

@Override
@SuppressWarnings("Interruption") // We are propagating an interrupt from a caller.
public void cancel(boolean mayInterruptIfRunning) {
/*
* Lock to ensure that a task cannot be rescheduled while a cancel is ongoing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ abstract class AggregateFuture<InputT extends @Nullable Object, OutputT extends
}

@Override
@SuppressWarnings("Interruption") // We are propagating an interrupt from a caller.
protected final void afterDone() {
super.afterDone();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,7 @@ public void run() {
* completed normally; {@code true} otherwise
*/
@CanIgnoreReturnValue
@SuppressWarnings("Interruption") // We are propagating an interrupt from a caller.
public boolean cancel(boolean mayInterruptIfRunning) {
logger.get().log(FINER, "cancelling {0}", this);
boolean cancelled = future.cancel(mayInterruptIfRunning);
Expand Down
1 change: 1 addition & 0 deletions guava/src/com/google/common/util/concurrent/Futures.java
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,7 @@ private void recordInputCompletion(
delegateIndex = delegates.size();
}

@SuppressWarnings("Interruption") // We are propagating an interrupt from a caller.
private void recordCompletion() {
if (incompleteOutputCount.decrementAndGet() == 0 && wasCancelled) {
for (ListenableFuture<? extends T> toCancel : inputFutures) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public final void run() {
}
}

@SuppressWarnings("Interruption") // We are restoring an interrupt on this thread.
private void waitForInterrupt(Thread currentThread) {
/*
* If someone called cancel(true), it is possible that the interrupted bit hasn't been set yet.
Expand Down Expand Up @@ -189,6 +190,7 @@ private void waitForInterrupt(Thread currentThread) {
* Interrupts the running task. Because this internally calls {@link Thread#interrupt()} which can
* in turn invoke arbitrary code it is not safe to call while holding a lock.
*/
@SuppressWarnings("Interruption") // We are implementing a user-requested interrupt.
final void interruptTask() {
// Since the Thread is replaced by DONE before run() invokes listeners or returns, if we succeed
// in this CAS, there's no risk of interrupting the wrong thread or interrupting a thread that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ protected String pendingToString() {
@SuppressWarnings({
"GoodTime", // should accept a java.time.Duration
"CatchingUnchecked", // sneaky checked exception
"Interruption", // We copy AbstractExecutorService.invokeAny. Maybe we shouldn't: b/227335009.
})
@J2ktIncompatible
@GwtIncompatible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
@J2ktIncompatible
@GwtIncompatible
@ElementTypesAreNonnullByDefault
// TODO: b/227335009 - Maybe change interruption behavior, but it requires thought.
@SuppressWarnings("Interruption")
public final class SimpleTimeLimiter implements TimeLimiter {

private final ExecutorService executor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ private static final class Fire<V extends @Nullable Object> implements Runnable
}

@Override
// TODO: b/227335009 - Maybe change interruption behavior, but it requires thought.
@SuppressWarnings("Interruption")
public void run() {
// If either of these reads return null then we must be after a successful cancel or another
// call to this method.
Expand Down

0 comments on commit 49776fd

Please sign in to comment.