C0urante commented on code in PR #11608: URL: https://github.com/apache/kafka/pull/11608#discussion_r934461017
########## connect/runtime/src/main/java/org/apache/kafka/connect/util/Closeables.java: ########## @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.kafka.connect.util; + +import org.apache.kafka.common.utils.Utils; +import org.apache.kafka.connect.runtime.isolation.LoaderSwap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.IdentityHashMap; +import java.util.Map; + +public class Closeables implements AutoCloseable { + + private static final Logger log = LoggerFactory.getLogger(Closeables.class); + + private final Map<AutoCloseable, String> closeables; + private ClassLoader loader; + + public Closeables() { + closeables = new IdentityHashMap<>(); + } + + public void register(AutoCloseable closeable, String name) { + if (closeable == null) { + log.trace("Ignoring null closeable {}", name); Review Comment: Good question--this should be handled gracefully by Log4j; the log message will be "Ignoring null closeable null". However, now that I think about it, I don't know if we should accommodate null names at all. I've tweaked the API here to require `name` to be non-null, and I've added Javadocs to the `Closeables` class and all of its methods, that make sure to call out which arguments may never be null. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
