Skip to content
Permalink
Browse files

Overload getResources in the DynamicClassLoader

Fix bug in is_proc
  • Loading branch information
LadyCailin committed Feb 22, 2020
1 parent f3aa395 commit 533b5ab9df885fa125f9b441065eedab7d1e3af9
@@ -6,7 +6,9 @@
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -18,8 +20,8 @@
*/
public class DynamicClassLoader extends ClassLoader {

private final Map<URL, URLClassLoader> classLoaders = new LinkedHashMap<URL, URLClassLoader>();
private final Set<URL> urls = new HashSet<URL>();
private final Map<URL, URLClassLoader> classLoaders = new LinkedHashMap<>();
private final Set<URL> urls = new HashSet<>();
private boolean destroyed = false;

/**
@@ -71,9 +73,32 @@ protected synchronized Package getPackage(String name) {
return null;
}

@Override
public Enumeration<URL> getResources(String name) throws IOException {
List<URL> locations = new ArrayList<>();
for(ClassLoader c : classLoaders.values()) {
Enumeration<URL> res = c.getResources(name);
while(res.hasMoreElements()) {
locations.add(res.nextElement());
}
}
Iterator<URL> iterator = locations.iterator();
return new Enumeration() {
@Override
public boolean hasMoreElements() {
return iterator.hasNext();
}

@Override
public Object nextElement() {
return iterator.next();
}
};
}

@Override
protected synchronized Package[] getPackages() {
List<Package> packages = new ArrayList<Package>();
List<Package> packages = new ArrayList<>();
for(ClassLoader c : classLoaders.values()) {
packages.addAll(Arrays.asList((Package[]) ReflectionUtils.invokeMethod(c.getClass(), c, "getPackages")));
}
@@ -118,7 +143,8 @@ public synchronized void destroy() {

private void checkDestroy() {
if(destroyed) {
throw new RuntimeException("Cannot access this instance of " + DynamicClassLoader.class.getSimpleName() + ", as it has already been destroyed.");
throw new RuntimeException("Cannot access this instance of " + DynamicClassLoader.class.getSimpleName()
+ ", as it has already been destroyed.");
}
}

@@ -92,7 +92,7 @@ public CClassType getExceptionType() {

/**
* Returns the name of the exception. If the exception is an instanceof AbstractCREException, this is equivalent to
* calling {@link #getName() }. Otherwise, the java class name is returned.
* calling {@link #getName()}. Otherwise, the java class name is returned.
*
* @param ex
* @return
@@ -1489,7 +1489,7 @@ public String profileMessageS(List<ParseTree> args) {

}

@api(environments = CommandHelperEnvironment.class)
@api
public static class is_proc extends AbstractFunction {

@Override

0 comments on commit 533b5ab

Please sign in to comment.
You can’t perform that action at this time.