@Test void childLoading() { Stream.of(true, false).forEach(parentFirst -> { final ClassLoader parent = ConfigurableClassLoaderTest.class.getClassLoader(); try (final ConfigurableClassLoader loader = new ConfigurableClassLoader("", new URL[] { new File(Constants.DEPENDENCIES_LOCATION, "org/apache/tomee/ziplock/7.0.5/ziplock-7.0.5.jar").toURI().toURL() }, parent, name -> true, name -> parentFirst, null, new String[0])) { try { loader.loadClass("org.apache.ziplock.JarLocation"); } catch (final ClassNotFoundException e) { fail("JarLocation can't be found: " + e.getMessage()); } try { parent.loadClass("org.apache.ziplock.JarLocation"); fail("Parent shouldn't be able to load JarLocation otherwise this test is pointless"); } catch (final ClassNotFoundException e) { } } catch (final IOException e) { fail(e.getMessage()); } }); }
@Override public Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException { if (name == null) { throw new ClassNotFoundException(); } final Class<?> aClass = proxies.get(name); if (aClass != null) { return aClass; } synchronized (getClassLoadingLock(name)) { Class<?> clazz; if (isDirectJvmClass(name)) { clazz = loadFromJvm(name, resolve); if (clazz != null) { return clazz; } } clazz = findLoadedClass(name); if (postLoad(resolve, clazz)) { return clazz; } final boolean childFirst = childFirstFilter.test(name); if (childFirst) { clazz = loadInternal(name, resolve); if (clazz != null) { return clazz; } } if (parentFilter.test(name)) { clazz = loadFromParent(name, resolve); if (clazz != null) { return clazz; } } if (!childFirst) { clazz = loadInternal(name, resolve); if (clazz != null) { return clazz; } } if (shouldFallbackOnJvmLoading(name)) { clazz = loadFromJvm(name, resolve); if (clazz != null) { return clazz; } } clazz = classLoaderFromClasspath.loadClass(name); if (clazz != null) { return clazz; } throw new ClassNotFoundException(name); } }
ConfigurableClassLoader extends URLClassLoader { @Override public Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException { if (name == null) { throw new ClassNotFoundException(); } final Class<?> aClass = proxies.get(name); if (aClass != null) { return aClass; } synchronized (getClassLoadingLock(name)) { Class<?> clazz; if (isDirectJvmClass(name)) { clazz = loadFromJvm(name, resolve); if (clazz != null) { return clazz; } } clazz = findLoadedClass(name); if (postLoad(resolve, clazz)) { return clazz; } final boolean childFirst = childFirstFilter.test(name); if (childFirst) { clazz = loadInternal(name, resolve); if (clazz != null) { return clazz; } } if (parentFilter.test(name)) { clazz = loadFromParent(name, resolve); if (clazz != null) { return clazz; } } if (!childFirst) { clazz = loadInternal(name, resolve); if (clazz != null) { return clazz; } } if (shouldFallbackOnJvmLoading(name)) { clazz = loadFromJvm(name, resolve); if (clazz != null) { return clazz; } } clazz = classLoaderFromClasspath.loadClass(name); if (clazz != null) { return clazz; } throw new ClassNotFoundException(name); } } }
ConfigurableClassLoader extends URLClassLoader { @Override public Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException { if (name == null) { throw new ClassNotFoundException(); } final Class<?> aClass = proxies.get(name); if (aClass != null) { return aClass; } synchronized (getClassLoadingLock(name)) { Class<?> clazz; if (isDirectJvmClass(name)) { clazz = loadFromJvm(name, resolve); if (clazz != null) { return clazz; } } clazz = findLoadedClass(name); if (postLoad(resolve, clazz)) { return clazz; } final boolean childFirst = childFirstFilter.test(name); if (childFirst) { clazz = loadInternal(name, resolve); if (clazz != null) { return clazz; } } if (parentFilter.test(name)) { clazz = loadFromParent(name, resolve); if (clazz != null) { return clazz; } } if (!childFirst) { clazz = loadInternal(name, resolve); if (clazz != null) { return clazz; } } if (shouldFallbackOnJvmLoading(name)) { clazz = loadFromJvm(name, resolve); if (clazz != null) { return clazz; } } clazz = classLoaderFromClasspath.loadClass(name); if (clazz != null) { return clazz; } throw new ClassNotFoundException(name); } } ConfigurableClassLoader(final String id, final URL[] urls, final ClassLoader parent,
            final Predicate<String> parentFilter, final Predicate<String> childFirstFilter,
            final String[] nestedDependencies, final String[] jvmPrefixes); private  ConfigurableClassLoader(final String id, final URL[] urls, final ClassLoader parent,
            final Predicate<String> parentFilter, final Predicate<String> childFirstFilter,
            final Map<String, Collection<Resource>> resources, final String[] jvmPrefixes); }
ConfigurableClassLoader extends URLClassLoader { @Override public Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException { if (name == null) { throw new ClassNotFoundException(); } final Class<?> aClass = proxies.get(name); if (aClass != null) { return aClass; } synchronized (getClassLoadingLock(name)) { Class<?> clazz; if (isDirectJvmClass(name)) { clazz = loadFromJvm(name, resolve); if (clazz != null) { return clazz; } } clazz = findLoadedClass(name); if (postLoad(resolve, clazz)) { return clazz; } final boolean childFirst = childFirstFilter.test(name); if (childFirst) { clazz = loadInternal(name, resolve); if (clazz != null) { return clazz; } } if (parentFilter.test(name)) { clazz = loadFromParent(name, resolve); if (clazz != null) { return clazz; } } if (!childFirst) { clazz = loadInternal(name, resolve); if (clazz != null) { return clazz; } } if (shouldFallbackOnJvmLoading(name)) { clazz = loadFromJvm(name, resolve); if (clazz != null) { return clazz; } } clazz = classLoaderFromClasspath.loadClass(name); if (clazz != null) { return clazz; } throw new ClassNotFoundException(name); } } ConfigurableClassLoader(final String id, final URL[] urls, final ClassLoader parent,
            final Predicate<String> parentFilter, final Predicate<String> childFirstFilter,
            final String[] nestedDependencies, final String[] jvmPrefixes); private  ConfigurableClassLoader(final String id, final URL[] urls, final ClassLoader parent,
            final Predicate<String> parentFilter, final Predicate<String> childFirstFilter,
            final Map<String, Collection<Resource>> resources, final String[] jvmPrefixes); Class<?> registerBytecode(final String name, final byte[] bytes); String[] getJvmMarkers(); void registerTransformer(final ClassFileTransformer transformer); synchronized URLClassLoader createTemporaryCopy(); @Override synchronized void close(); @Override Class<?> loadClass(final String name, final boolean resolve); @Override URL findResource(final String name); @Override Enumeration<URL> getResources(final String name); @Override URL getResource(final String name); @Override InputStream getResourceAsStream(final String name); @Override Enumeration<URL> findResources(final String name); List<InputStream> findContainedResources(final String name); }
ConfigurableClassLoader extends URLClassLoader { @Override public Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException { if (name == null) { throw new ClassNotFoundException(); } final Class<?> aClass = proxies.get(name); if (aClass != null) { return aClass; } synchronized (getClassLoadingLock(name)) { Class<?> clazz; if (isDirectJvmClass(name)) { clazz = loadFromJvm(name, resolve); if (clazz != null) { return clazz; } } clazz = findLoadedClass(name); if (postLoad(resolve, clazz)) { return clazz; } final boolean childFirst = childFirstFilter.test(name); if (childFirst) { clazz = loadInternal(name, resolve); if (clazz != null) { return clazz; } } if (parentFilter.test(name)) { clazz = loadFromParent(name, resolve); if (clazz != null) { return clazz; } } if (!childFirst) { clazz = loadInternal(name, resolve); if (clazz != null) { return clazz; } } if (shouldFallbackOnJvmLoading(name)) { clazz = loadFromJvm(name, resolve); if (clazz != null) { return clazz; } } clazz = classLoaderFromClasspath.loadClass(name); if (clazz != null) { return clazz; } throw new ClassNotFoundException(name); } } ConfigurableClassLoader(final String id, final URL[] urls, final ClassLoader parent,
            final Predicate<String> parentFilter, final Predicate<String> childFirstFilter,
            final String[] nestedDependencies, final String[] jvmPrefixes); private  ConfigurableClassLoader(final String id, final URL[] urls, final ClassLoader parent,
            final Predicate<String> parentFilter, final Predicate<String> childFirstFilter,
            final Map<String, Collection<Resource>> resources, final String[] jvmPrefixes); Class<?> registerBytecode(final String name, final byte[] bytes); String[] getJvmMarkers(); void registerTransformer(final ClassFileTransformer transformer); synchronized URLClassLoader createTemporaryCopy(); @Override synchronized void close(); @Override Class<?> loadClass(final String name, final boolean resolve); @Override URL findResource(final String name); @Override Enumeration<URL> getResources(final String name); @Override URL getResource(final String name); @Override InputStream getResourceAsStream(final String name); @Override Enumeration<URL> findResources(final String name); List<InputStream> findContainedResources(final String name); static final String NESTED_MAVEN_REPOSITORY; }