protected LoaderSwap withClassLoader(ClassLoader loader) {
        ClassLoader savedLoader = Plugins.compareAndSwapLoaders(loader);
        try {
            return new LoaderSwap(savedLoader);
        } catch (Throwable t) {
            Plugins.compareAndSwapLoaders(savedLoader);
            throw t;
        }
    }
Helper to evaluate a {@link ServiceLoader} operation while handling {@link LinkageError}s.

@param type The plugin type which is being loaded
@param function A function on a {@link ServiceLoader}'s {@link Iterator} which may throw {@link LinkageError}
@return the return value of function
@throws Error errors thrown by the passed-in function
@param <U> Return value of the passed-in function
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/isolation/PluginScanner.java