BytecodeClassLoader loader = null;
if (classLoader instanceof SourceClassLoader) {
loader = ((SourceClassLoader)classLoader).findBytecodeClassLoaderBySource(source);
}
if (loader == null) {
throw new LoadException("Source not found: " + source);
}
if (!loader.code.getClassNames(source).contains(name)) {
throw new LoadException("Class '" + name + "' not found for source. Source: " + source);
}
Class<?> clazz = loader.loadClassFromBytecode(name);
if (clazz == null) {
throw new LoadException("Inconsistent code: " + loader.code +
". Class '" + name + "' not found for source. Source: " + source);
}
return clazz;
}