This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-bcel.git
The following commit(s) were added to refs/heads/master by this push: new afbf9cab ClassPath.getResources(String) can use an ArrayList instead of a Vector afbf9cab is described below commit afbf9cab23f276df28a8f5cb4ca4867d267dc52a Author: Gary D. Gregory <garydgreg...@gmail.com> AuthorDate: Thu Mar 20 11:41:24 2025 -0400 ClassPath.getResources(String) can use an ArrayList instead of a Vector - Add missing test --- src/changes/changes.xml | 1 + src/main/java/org/apache/bcel/util/ClassPath.java | 8 ++++---- src/test/java/org/apache/bcel/util/ClassPathTestCase.java | 6 ++++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 82a1bbfb..a78332d8 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -64,6 +64,7 @@ The <action> type attribute can be add,update,fix,remove. <action type="fix" dev="ggregory" due-to="Gary Gregory">Replace internal use of Locale.ENGLISH with Locale.ROOT.</action> <action issue="BCEL-375" type="fix" dev="ggregory" due-to="J. Lewis Muir, Gary Gregory">Wrong permissions on bcel .jar file in binary .tar.gz distribution file.</action> <action issue="BCEL-376" type="fix" dev="ggregory" due-to="Dominik Stadler, Gary Gregory">ClassPath.close() throws UnsupportedOperationException when created with system-classpath.</action> + <action type="fix" dev="ggregory" due-to="Gary Gregory">ClassPath.getResources(String) can use an ArrayList instead of a Vector.</action> <!-- ADD --> <action type="update" dev="ggregory" due-to="Gary Gregory">Add Const.MAJOR_25.</action> <action type="update" dev="ggregory" due-to="Gary Gregory">Add Const.MINOR_25.</action> diff --git a/src/main/java/org/apache/bcel/util/ClassPath.java b/src/main/java/org/apache/bcel/util/ClassPath.java index 513cf52f..a77d5740 100644 --- a/src/main/java/org/apache/bcel/util/ClassPath.java +++ b/src/main/java/org/apache/bcel/util/ClassPath.java @@ -32,12 +32,12 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Enumeration; import java.util.List; import java.util.Locale; import java.util.Objects; import java.util.StringTokenizer; -import java.util.Vector; import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -767,14 +767,14 @@ public class ClassPath implements Closeable { * @since 6.0 */ public Enumeration<URL> getResources(final String name) { - final Vector<URL> results = new Vector<>(); + final List<URL> list = new ArrayList<>(); for (final AbstractPathEntry path : paths) { final URL url; if ((url = path.getResource(name)) != null) { - results.add(url); + list.add(url); } } - return results.elements(); + return Collections.enumeration(list); } @Override diff --git a/src/test/java/org/apache/bcel/util/ClassPathTestCase.java b/src/test/java/org/apache/bcel/util/ClassPathTestCase.java index b69599d5..c6de8a11 100644 --- a/src/test/java/org/apache/bcel/util/ClassPathTestCase.java +++ b/src/test/java/org/apache/bcel/util/ClassPathTestCase.java @@ -19,6 +19,7 @@ package org.apache.bcel.util; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.io.InputStream; @@ -51,4 +52,9 @@ public class ClassPathTestCase extends AbstractTestCase { assertNotNull(inputStream); } } + + @Test + public void testGetResources() { + assertTrue(ClassPath.SYSTEM_CLASS_PATH.getResources("java/lang/String.class").hasMoreElements()); + } }