@Override
    protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
        // has the class loaded already?
        Class<?> loadedClass = findLoadedClass(name);
        if (loadedClass == null) {
            try {
                // find the class from given jar urls as in first constructor parameter.
                loadedClass = findClass(name);
            } catch (ClassNotFoundException ignored) {
                // ignore class not found
            }

            if (loadedClass == null) {
                loadedClass = getParent().loadClass(name);
            }

            if (loadedClass == null) {
                throw new ClassNotFoundException("Could not find class " + name + " in classloader nor in parent classloader");
            }
        }

        if (resolve) {
            resolveClass(loadedClass);
        }
        return loadedClass;
    }
@Test
    public void prefersClassInParentBeforeIntermediate() throws Exception {
        URL testClassesUrl = new File("./target/test-classes").toURI().toURL();

        URLClassLoader intermediateCl = new URLClassLoader(new URL[]{testClassesUrl}, ClassLoader.getSystemClassLoader());
        cl = new ChildFirstClassLoader(new URL[]{emptyJarUrl},
                intermediateCl);

        String className = ChildFirstClassLoaderTest.class.getName();
        Class<?> clazz = cl.loadClass(className);
        assertThat(clazz).isNotNull();
        assertThat(clazz.getName()).isEqualTo(className);
        assertThat(clazz.getClassLoader()).isEqualTo(ClassLoader.getSystemClassLoader());
    }