C0urante commented on code in PR #13971: URL: https://github.com/apache/kafka/pull/13971#discussion_r1267236920
########## connect/runtime/src/main/java/org/apache/kafka/connect/runtime/isolation/PluginScanner.java: ########## @@ -118,35 +120,80 @@ private void loadJdbcDrivers(final ClassLoader loader) { } @SuppressWarnings({"rawtypes", "unchecked"}) - protected <T> PluginDesc<T> pluginDesc(Class<? extends T> plugin, String version, ClassLoader loader) { - return new PluginDesc(plugin, version, loader); + protected <T> PluginDesc<T> pluginDesc(Class<? extends T> plugin, String version, PluginSource source) { + return new PluginDesc(plugin, version, source.loader()); } @SuppressWarnings("unchecked") - protected <T> SortedSet<PluginDesc<T>> getServiceLoaderPluginDesc(Class<T> klass, ClassLoader loader) { + protected <T> SortedSet<PluginDesc<T>> getServiceLoaderPluginDesc(Class<T> klass, PluginSource source) { SortedSet<PluginDesc<T>> result = new TreeSet<>(); - ServiceLoader<T> serviceLoader = ServiceLoader.load(klass, loader); - for (Iterator<T> iterator = serviceLoader.iterator(); iterator.hasNext(); ) { - try (LoaderSwap loaderSwap = withClassLoader(loader)) { + ServiceLoader<T> serviceLoader = handleLinkageError(klass, source, () -> ServiceLoader.load(klass, source.loader())); Review Comment: I think that given the low likelihood of ever hitting this error when invoking `ServiceLoader::load` or `ServiceLoader::iterator` (neither is annotated with any kind of `throws` declaration, the iterator is specifically called out as being lazy-loading, and I'm not aware of any JDK bug reports that would lead to this kind of behavior), it's better to throw errors to the caller. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org