KAFKA-19178 Replace Vector by ArrayList for PluginClassLoader#getResources (#19529)

The vector is a synchronized collection, and in the case we don't need
to sync. Also, we can use `Collections.enumeration` to convert
collection to enumeration easily.

Reviewers: PoAn Yang <payang@apache.org>, Ken Huang
 <s7133700@gmail.com>, Chia-Ping Tsai <chia7712@gmail.com>
This commit is contained in:
Nick Guo 2025-04-26 23:39:02 +08:00 committed by GitHub
parent 0cf2f0e55d
commit 51ef2903f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 3 deletions

View File

@ -22,9 +22,11 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.Objects;
import java.util.Vector;
/**
* A custom classloader dedicated to loading Connect plugin classes in classloading isolation.
@ -87,7 +89,7 @@ public class PluginClassLoader extends URLClassLoader {
@Override
public Enumeration<URL> getResources(String name) throws IOException {
Objects.requireNonNull(name);
Vector<URL> resources = new Vector<>();
List<URL> resources = new ArrayList<>();
for (Enumeration<URL> foundLocally = findResources(name); foundLocally.hasMoreElements();) {
URL url = foundLocally.nextElement();
if (url != null)
@ -99,7 +101,7 @@ public class PluginClassLoader extends URLClassLoader {
if (url != null)
resources.add(url);
}
return resources.elements();
return Collections.enumeration(resources);
}
// This method needs to be thread-safe because it is supposed to be called by multiple