ClassLoader () { ClassLoader loader = myLoader; if (loader != null) { return loader; } final URLClassLoader platformLoader = myPlatformUrls.length > 0 ? new URLClassLoader(myPlatformUrls, null) : null; final ClassLoader cpLoader = new URLClassLoader(myClasspathUrls, platformLoader); loader = new ClassLoader(cpLoader) { @Override public InputStream getResourceAsStream(String name) { InputStream is = super.getResourceAsStream(name); if (is == null) { try { is = InstrumentationClassFinder.this.getResourceAsStream(name); } catch (IOException ignored) { } } return is; } @Override protected Class findClass(String name) throws ClassNotFoundException { final InputStream is = lookupClassBeforeClasspath(name.replace('.', '/')); if (is == null) { throw new ClassNotFoundException("Class not found: " + name.replace('/', '.')); // ensure presentable class name in error message } try { final byte[] bytes = loadBytes(is); return defineClass(name.replace('/', '.'), bytes, 0, bytes.length); } finally { try { is.close(); } catch (IOException ignored) { } } } }; myLoader = loader; return loader; }