Skip to content

Commit

Permalink
Merge pull request #927 from mselerin/3.8.x
Browse files Browse the repository at this point in the history
fix: CompositeClassLoader does not implement getResource(String)
  • Loading branch information
SteveDonie committed Feb 21, 2020
2 parents 5003e26 + 248af4c commit 586eb88
Showing 1 changed file with 29 additions and 1 deletion.
Expand Up @@ -4,6 +4,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.*;

/**
Expand Down Expand Up @@ -95,12 +96,39 @@ public Class loadClass(String name,boolean resolve) throws ClassNotFoundExceptio
} else {
throw new ClassNotFoundException(name);
}
}


@Override
public URL getResource(String name) {
for (ClassLoader cl : classLoaders) {
URL url = cl.getResource(name);
if (url != null)
return url;
}

// Try with the context class loader associated with the current thread.
return Thread.currentThread().getContextClassLoader().getResource(name);
}


@Override
public Enumeration<URL> getResources(String name) throws IOException {
List<URL> urls = new ArrayList<>();

for (ClassLoader cl : classLoaders) {
Enumeration<URL> resources = cl.getResources(name);
while (resources.hasMoreElements()) {
urls.add(resources.nextElement());
}
}

if (!urls.isEmpty()) {
return Collections.enumeration(urls);
}

// Try with the context class loader associated with the current thread.
return Thread.currentThread().getContextClassLoader().getResources(name);
}
}

@Override
Expand Down

0 comments on commit 586eb88

Please sign in to comment.