Fixed #5414
This commit is contained in:
@@ -4,7 +4,12 @@ import arc.struct.*;
|
||||
|
||||
public class ModClassLoader extends ClassLoader{
|
||||
private Seq<ClassLoader> children = new Seq<>();
|
||||
private volatile boolean inChild = false;
|
||||
private ThreadLocal<Boolean> inChild = new ThreadLocal<>(){
|
||||
@Override
|
||||
protected Boolean initialValue(){
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
};
|
||||
|
||||
public void addChild(ClassLoader child){
|
||||
children.add(child);
|
||||
@@ -13,15 +18,15 @@ public class ModClassLoader extends ClassLoader{
|
||||
@Override
|
||||
protected Class<?> findClass(String name) throws ClassNotFoundException{
|
||||
//a child may try to delegate class loading to its parent, which is *this class loader* - do not let that happen
|
||||
if(inChild){
|
||||
inChild = false;
|
||||
if(inChild.get()){
|
||||
inChild.set(false);
|
||||
throw new ClassNotFoundException(name);
|
||||
}
|
||||
|
||||
ClassNotFoundException last = null;
|
||||
int size = children.size;
|
||||
|
||||
inChild = true;
|
||||
inChild.set(true);
|
||||
//if it doesn't exist in the main class loader, try all the children
|
||||
for(int i = 0; i < size; i++){
|
||||
try{
|
||||
@@ -30,7 +35,7 @@ public class ModClassLoader extends ClassLoader{
|
||||
last = e;
|
||||
}
|
||||
}
|
||||
inChild = false;
|
||||
inChild.set(false);
|
||||
|
||||
throw (last == null ? new ClassNotFoundException(name) : last);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user