From 077142a42b879e3f76c71b8d8ac0e606b6084bc5 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Tue, 24 Sep 2024 07:49:54 -0400 Subject: [PATCH] A FutureContribution should not allow a null BasicFuture (#485) --- .../hc/core5/concurrent/FutureContribution.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/httpcore5/src/main/java/org/apache/hc/core5/concurrent/FutureContribution.java b/httpcore5/src/main/java/org/apache/hc/core5/concurrent/FutureContribution.java index fde61517e..de1f68eb9 100644 --- a/httpcore5/src/main/java/org/apache/hc/core5/concurrent/FutureContribution.java +++ b/httpcore5/src/main/java/org/apache/hc/core5/concurrent/FutureContribution.java @@ -26,6 +26,8 @@ */ package org.apache.hc.core5.concurrent; +import java.util.Objects; + /** * Convenience base class for {@link FutureCallback}s that contribute a result * of the operation to another {@link BasicFuture}. @@ -40,24 +42,20 @@ public abstract class FutureContribution implements FutureCallback { /** * Constructs a new instance to callback the given {@link BasicFuture}. * - * @param future The callback. + * @param future The callback, non-null. */ public FutureContribution(final BasicFuture future) { - this.future = future; + this.future = Objects.requireNonNull(future); } @Override public final void failed(final Exception ex) { - if (future != null) { - future.failed(ex); - } + future.failed(ex); } @Override public final void cancelled() { - if (future != null) { - future.cancel(); - } + future.cancel(); } @SuppressWarnings("unchecked")