Override loadClass with two arguments in MemoryBasedClassLoader

This commit is contained in:
Yan Zhulanow
2015-03-10 21:09:26 +03:00
parent 7b39cf4998
commit f564734be2
@@ -41,22 +41,22 @@ public class MemoryBasedClassLoader extends ClassLoader {
} }
@Override @Override
public Class<?> loadClass(String name) throws ClassNotFoundException { protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
if (classesToLoadByParent != null && classesToLoadByParent.accept(name)) { if (classesToLoadByParent != null && classesToLoadByParent.accept(name)) {
if (parent == null) { if (parent == null) {
return super.loadClass(name); return super.loadClass(name, resolve);
} }
try { try {
return parent.loadClass(name); return parent.loadClass(name);
} }
catch (ClassNotFoundException e) { catch (ClassNotFoundException e) {
return super.loadClass(name); return super.loadClass(name, resolve);
} }
} }
// Look in this class loader and then in the parent one // Look in this class loader and then in the parent one
Class<?> aClass = super.loadClass(name); Class<?> aClass = super.loadClass(name, resolve);
if (aClass == null) { if (aClass == null) {
if (parent == null) { if (parent == null) {
throw new ClassNotFoundException("Class not available in preloader: " + name); throw new ClassNotFoundException("Class not available in preloader: " + name);
@@ -66,6 +66,11 @@ public class MemoryBasedClassLoader extends ClassLoader {
return aClass; return aClass;
} }
@Override
public Class<?> loadClass(String name) throws ClassNotFoundException {
return loadClass(name, false);
}
@Override @Override
protected Class<?> findClass(String name) throws ClassNotFoundException { protected Class<?> findClass(String name) throws ClassNotFoundException {
String internalName = name.replace('.', '/').concat(".class"); String internalName = name.replace('.', '/').concat(".class");