@Override
    protected Class<?> loadClass(final String name, final boolean resolve)
            throws ClassNotFoundException {
        synchronized (getClassLoadingLock(name)) {
            try {
                final Class<?> loadedClass = findLoadedClass(name);
                if (loadedClass != null) {
                    return resolveIfNeeded(resolve, loadedClass);
                }

                if (isComponentFirstClass(name)) {
                    return loadClassFromComponentFirst(name, resolve);
                }
                if (isOwnerFirstClass(name)) {
                    return loadClassFromOwnerFirst(name, resolve);
                }

                // making this behavior configurable (component-only/component-first/owner-first)
                // would allow this class to subsume the FlinkUserCodeClassLoader (with an added
                // exception handler)
                return loadClassFromComponentOnly(name, resolve);
            } catch (ClassNotFoundException e) {
                // If we know the package of this class
                Optional<String> foundAssociatedModule =
                        knownPackagePrefixesModuleAssociation.entrySet().stream()
                                .filter(entry -> name.startsWith(entry.getKey()))
                                .map(Map.Entry::getValue)
                                .findFirst();
                if (foundAssociatedModule.isPresent()) {
                    throw new ClassNotFoundException(
                            String.format(
                                    "Class '%s' not found. Perhaps you forgot to add the module '%s' to the classpath?",
                                    name, foundAssociatedModule.get()),
                            e);
                }
                throw e;
            }
        }
    }
@Test
    void testComponentOnlyIsDefaultForClasses() throws Exception {
        assertThatExceptionOfType(ClassNotFoundException.class)
                .isThrownBy(
                        () -> {
                            TestUrlClassLoader owner =
                                    new TestUrlClassLoader(
                                            NON_EXISTENT_CLASS_NAME, CLASS_RETURNED_BY_OWNER);

                            final ComponentClassLoader componentClassLoader =
                                    new ComponentClassLoader(
                                            new URL[0],
                                            owner,
                                            new String[0],
                                            new String[0],
                                            Collections.emptyMap());

                            componentClassLoader.loadClass(NON_EXISTENT_CLASS_NAME);
                        });
    }