From 746a638df9f1a303f7ffc2b445f692b503d2f270 Mon Sep 17 00:00:00 2001 From: Jian Date: Wed, 4 Feb 2026 17:37:52 +0800 Subject: [PATCH 1/2] Minor: remove an unused method and adjust method visibility Removed the safe method that returns an empty list for null input. --- .../java/org/apache/kafka/common/utils/Utils.java | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/clients/src/main/java/org/apache/kafka/common/utils/Utils.java b/clients/src/main/java/org/apache/kafka/common/utils/Utils.java index 51cb86f5c88b9..626054d35b113 100644 --- a/clients/src/main/java/org/apache/kafka/common/utils/Utils.java +++ b/clients/src/main/java/org/apache/kafka/common/utils/Utils.java @@ -901,22 +901,10 @@ public FileVisitResult postVisitDirectory(Path path, IOException exc) throws IOE }); } - /** - * Returns an empty list if the provided list is null, otherwise returns the list itself. - *

- * This method is useful for avoiding {@code NullPointerException} when working with potentially null lists. - * - * @param other the list to check for null - * @return an empty list if the provided list is null, otherwise the original list - */ - public static List safe(List other) { - return other == null ? Collections.emptyList() : other; - } - /** * Get the ClassLoader which loaded Kafka. */ - public static ClassLoader getKafkaClassLoader() { + private static ClassLoader getKafkaClassLoader() { return Utils.class.getClassLoader(); } From a5c3fda90fb3c5d502ac0b1718bc0a28c4304cb7 Mon Sep 17 00:00:00 2001 From: Jian Date: Thu, 5 Feb 2026 06:29:27 +0800 Subject: [PATCH 2/2] inline the method call Removed the private method getKafkaClassLoader and replaced its usage. --- .../main/java/org/apache/kafka/common/utils/Utils.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/clients/src/main/java/org/apache/kafka/common/utils/Utils.java b/clients/src/main/java/org/apache/kafka/common/utils/Utils.java index 626054d35b113..f8b8456d5f8d7 100644 --- a/clients/src/main/java/org/apache/kafka/common/utils/Utils.java +++ b/clients/src/main/java/org/apache/kafka/common/utils/Utils.java @@ -901,13 +901,6 @@ public FileVisitResult postVisitDirectory(Path path, IOException exc) throws IOE }); } - /** - * Get the ClassLoader which loaded Kafka. - */ - private static ClassLoader getKafkaClassLoader() { - return Utils.class.getClassLoader(); - } - /** * Get the Context ClassLoader on this thread or, if not present, the ClassLoader that * loaded Kafka. @@ -917,7 +910,7 @@ private static ClassLoader getKafkaClassLoader() { public static ClassLoader getContextOrKafkaClassLoader() { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl == null) - return getKafkaClassLoader(); + return Utils.class.getClassLoader(); else return cl; }