diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/ThrottledProgressEventDispatcherWrapper.java b/jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/ThrottledProgressEventDispatcherWrapper.java index 26a8de1612..e29b495307 100644 --- a/jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/ThrottledProgressEventDispatcherWrapper.java +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/ThrottledProgressEventDispatcherWrapper.java @@ -20,6 +20,7 @@ import com.google.cloud.tools.jib.event.progress.ThrottledAccumulatingConsumer; import com.google.common.base.Preconditions; import java.io.Closeable; +import java.util.Objects; import javax.annotation.Nullable; /** @@ -45,16 +46,21 @@ class ThrottledProgressEventDispatcherWrapper implements Closeable { } public void dispatchProgress(Long progressUnits) { - Preconditions.checkNotNull(throttledDispatcher); + Objects.requireNonNull(throttledDispatcher); throttledDispatcher.accept(progressUnits); } @Override public void close() { - Preconditions.checkNotNull(progressEventDispatcher); - Preconditions.checkNotNull(throttledDispatcher); - throttledDispatcher.close(); - progressEventDispatcher.close(); + try { + if (throttledDispatcher != null) { + throttledDispatcher.close(); + } + } finally { + if (progressEventDispatcher != null) { + progressEventDispatcher.close(); + } + } } void setProgressTarget(long allocationUnits) {