1
0

Fix generics warnings in tests

This commit is contained in:
Gary Gregory
2024-08-14 08:37:12 -04:00
parent 1e987dcace
commit 1002f11bad

View File

@@ -66,7 +66,7 @@ public class PathableClassLoader extends URLClassLoader {
* Normally, only a class loader created with a null parent needs to * Normally, only a class loader created with a null parent needs to
* have any lookasides defined. * have any lookasides defined.
*/ */
private HashMap lookasides; private HashMap<String, ClassLoader> lookasides;
/** /**
* See setParentFirst. * See setParentFirst.
@@ -127,8 +127,7 @@ public class PathableClassLoader extends URLClassLoader {
if (!file.exists()) { if (!file.exists()) {
Assert.fail("Unable to add logical library " + fileName); Assert.fail("Unable to add logical library " + fileName);
} }
final URL libUrl = file.toURL(); addURL(file.toURL());
addURL(libUrl);
return; return;
} catch (final java.net.MalformedURLException e) { } catch (final java.net.MalformedURLException e) {
throw new UnknownError( throw new UnknownError(
@@ -216,12 +215,11 @@ public class PathableClassLoader extends URLClassLoader {
* it's declared final in java1.4 (thought that's been removed for 1.5). * it's declared final in java1.4 (thought that's been removed for 1.5).
* The inherited implementation always behaves as if parentFirst=true. * The inherited implementation always behaves as if parentFirst=true.
*/ */
public Enumeration getResourcesInOrder(final String name) throws IOException { public Enumeration<URL> getResourcesInOrder(final String name) throws IOException {
if (parentFirst) { if (parentFirst) {
return super.getResources(name); return super.getResources(name);
} }
final Enumeration localUrls = super.findResources(name); final Enumeration<URL> localUrls = super.findResources(name);
final ClassLoader parent = getParent(); final ClassLoader parent = getParent();
if (parent == null) { if (parent == null) {
// Alas, there is no method to get matching resources // Alas, there is no method to get matching resources
@@ -236,10 +234,9 @@ public class PathableClassLoader extends URLClassLoader {
// path! // path!
return localUrls; return localUrls;
} }
final Enumeration parentUrls = parent.getResources(name); final Enumeration<URL> parentUrls = parent.getResources(name);
final ArrayList<URL> localItems = toList(localUrls);
final ArrayList localItems = toList(localUrls); final ArrayList<URL> parentItems = toList(parentUrls);
final ArrayList parentItems = toList(parentUrls);
localItems.addAll(parentItems); localItems.addAll(parentItems);
return Collections.enumeration(localItems); return Collections.enumeration(localItems);
} }
@@ -312,11 +309,10 @@ public class PathableClassLoader extends URLClassLoader {
} }
if (lookasides != null) { if (lookasides != null) {
for (final Object element : lookasides.entrySet()) { for (final Map.Entry<String, ClassLoader> entry : lookasides.entrySet()) {
final Map.Entry entry = (Map.Entry) element; final String prefix = entry.getKey();
final String prefix = (String) entry.getKey();
if (name.startsWith(prefix)) { if (name.startsWith(prefix)) {
final ClassLoader loader = (ClassLoader) entry.getValue(); final ClassLoader loader = entry.getValue();
return Class.forName(name, resolve, loader); return Class.forName(name, resolve, loader);
} }
} }
@@ -366,12 +362,11 @@ public class PathableClassLoader extends URLClassLoader {
* @return {@code ArrayList} containing the enumerated * @return {@code ArrayList} containing the enumerated
* elements in the enumerated order, not null * elements in the enumerated order, not null
*/ */
private ArrayList toList(final Enumeration en) { private <E> ArrayList<E> toList(final Enumeration<E> en) {
final ArrayList results = new ArrayList(); final ArrayList<E> results = new ArrayList<>();
if (en != null) { if (en != null) {
while (en.hasMoreElements()) { while (en.hasMoreElements()) {
final Object element = en.nextElement(); results.add(en.nextElement());
results.add(element);
} }
} }
return results; return results;
@@ -404,7 +399,7 @@ public class PathableClassLoader extends URLClassLoader {
*/ */
public void useExplicitLoader(final String prefix, final ClassLoader loader) { public void useExplicitLoader(final String prefix, final ClassLoader loader) {
if (lookasides == null) { if (lookasides == null) {
lookasides = new HashMap(); lookasides = new HashMap<>();
} }
lookasides.put(prefix, loader); lookasides.put(prefix, loader);
} }