Skip to content
代码片段 群组 项目
未验证 提交 3ddb6231 编辑于 作者: vamossagar12's avatar vamossagar12 提交者: GitHub
浏览文件

KAFKA-14012: Add warning to closeQuietly documentation about method references...

KAFKA-14012: Add warning to closeQuietly documentation about method references of null objects (#12321)

Reviewers: Kvicii <42023367+Kvicii@users.noreply.github.com>, Chris Egerton <fearthecellos@gmail.com>
上级 a5d71e15
No related branches found
No related tags found
无相关合并请求
......@@ -998,6 +998,14 @@ public final class Utils {
/**
* Closes {@code closeable} and if an exception is thrown, it is logged at the WARN level.
* <b>Be cautious when passing method references as an argument.</b> For example:
* <p>
* {@code closeQuietly(task::stop, "source task");}
* <p>
* Although this method gracefully handles null {@link AutoCloseable} objects, attempts to take a method
* reference from a null object will result in a {@link NullPointerException}. In the example code above,
* it would be the caller's responsibility to ensure that {@code task} was non-null before attempting to
* use a method reference from it.
*/
public static void closeQuietly(AutoCloseable closeable, String name) {
if (closeable != null) {
......@@ -1009,6 +1017,17 @@ public final class Utils {
}
}
/**
* Closes {@code closeable} and if an exception is thrown, it is registered to the firstException parameter.
* <b>Be cautious when passing method references as an argument.</b> For example:
* <p>
* {@code closeQuietly(task::stop, "source task");}
* <p>
* Although this method gracefully handles null {@link AutoCloseable} objects, attempts to take a method
* reference from a null object will result in a {@link NullPointerException}. In the example code above,
* it would be the caller's responsibility to ensure that {@code task} was non-null before attempting to
* use a method reference from it.
*/
public static void closeQuietly(AutoCloseable closeable, String name, AtomicReference<Throwable> firstException) {
if (closeable != null) {
try {
......
......@@ -59,6 +59,7 @@ import org.slf4j.LoggerFactory;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
......@@ -235,7 +236,7 @@ public abstract class AbstractWorkerSourceTask extends WorkerTask {
this.admin = admin;
this.offsetReader = offsetReader;
this.offsetWriter = offsetWriter;
this.offsetStore = offsetStore;
this.offsetStore = Objects.requireNonNull(offsetStore, "offset store cannot be null for source tasks");
this.closeExecutor = closeExecutor;
this.sourceTaskContext = sourceTaskContext;
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册