mirror of
https://github.com/corda/corda.git
synced 2025-01-06 05:04:20 +00:00
Consider all class path elements in SystemClassLoader#findResources
The findResources method is supposed to enumerate all the class path elements' matching paths' URLs, but we used to stop at the first one. While this is good enough when the system class path contains only a single .jar file, since b88438d2(sketch of JAR support in Finder) supports more than a single .jar file in the class path. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
parent
1864180ea7
commit
0602d4a447
@ -17,6 +17,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
public class SystemClassLoader extends ClassLoader {
|
||||
private native VMClass findVMClass(String name)
|
||||
@ -114,12 +115,43 @@ public class SystemClassLoader extends ClassLoader {
|
||||
return Collections.enumeration(urls);
|
||||
}
|
||||
|
||||
protected Enumeration<URL> findResources(String name) {
|
||||
Collection<URL> urls = new ArrayList(1);
|
||||
URL url = findResource(name);
|
||||
if (url != null) {
|
||||
urls.add(url);
|
||||
private class ResourceEnumeration implements Enumeration<URL> {
|
||||
private long[] finderElementPtrPtr;
|
||||
private String name, urlPrefix;
|
||||
|
||||
public ResourceEnumeration(String name) {
|
||||
this.name = name;
|
||||
finderElementPtrPtr = new long[1];
|
||||
urlPrefix = nextResourceURLPrefix();
|
||||
}
|
||||
return Collections.enumeration(urls);
|
||||
|
||||
private native String nextResourceURLPrefix(SystemClassLoader loader,
|
||||
String name, long[] finderElementPtrPtr);
|
||||
|
||||
private String nextResourceURLPrefix() {
|
||||
return nextResourceURLPrefix(SystemClassLoader.this, name,
|
||||
finderElementPtrPtr);
|
||||
}
|
||||
|
||||
public boolean hasMoreElements() {
|
||||
return urlPrefix != null;
|
||||
}
|
||||
|
||||
public URL nextElement() {
|
||||
if (urlPrefix == null) throw new NoSuchElementException();
|
||||
URL result;
|
||||
try {
|
||||
result = new URL(urlPrefix + name);
|
||||
} catch (MalformedURLException ignored) {
|
||||
result = null;
|
||||
}
|
||||
if (finderElementPtrPtr[0] == 0l) urlPrefix = null;
|
||||
else urlPrefix = nextResourceURLPrefix();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
protected Enumeration<URL> findResources(String name) {
|
||||
return new ResourceEnumeration(name);
|
||||
}
|
||||
}
|
||||
|
@ -152,6 +152,30 @@ Avian_avian_SystemClassLoader_resourceURLPrefix
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT int64_t JNICALL
|
||||
Avian_avian_SystemClassLoader_00024ResourceEnumeration_nextResourceURLPrefix
|
||||
(Thread* t, object, uintptr_t* arguments)
|
||||
{
|
||||
object loader = reinterpret_cast<object>(arguments[1]);
|
||||
object name = reinterpret_cast<object>(arguments[2]);
|
||||
object finderElementPtrPtr = reinterpret_cast<object>(arguments[3]);
|
||||
|
||||
if (LIKELY(name) && LIKELY(finderElementPtrPtr)) {
|
||||
THREAD_RUNTIME_ARRAY(t, char, n, stringLength(t, name) + 1);
|
||||
stringChars(t, name, RUNTIME_ARRAY_BODY(n));
|
||||
|
||||
void *&finderElementPtr = reinterpret_cast<void *&>(longArrayBody(t,
|
||||
finderElementPtrPtr, 0));
|
||||
const char* name = static_cast<Finder*>
|
||||
(systemClassLoaderFinder(t, loader))->nextUrlPrefix(RUNTIME_ARRAY_BODY(n),
|
||||
finderElementPtr);
|
||||
|
||||
return name ? reinterpret_cast<uintptr_t>(makeString(t, "%s", name)) : 0;
|
||||
} else {
|
||||
throwNew(t, Machine::NullPointerExceptionType);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT int64_t JNICALL
|
||||
Avian_avian_SystemClassLoader_getClass
|
||||
(Thread* t, object, uintptr_t* arguments)
|
||||
|
Loading…
Reference in New Issue
Block a user