From fa2039fc1e5eb73c8897634a27f7ccda66719ab8 Mon Sep 17 00:00:00 2001 From: Konstantine Karantasis Date: Fri, 5 Oct 2018 12:46:13 -0700 Subject: [PATCH] KAFKA-6914; Set parent classloader of DelegatingClassLoader same as the worker's (#5720) The parent classloader of the DelegatingClassLoader and therefore the classloading scheme used by Connect does not have to be fixed to the System classloader. Setting it the same as the one that was used to load the DelegatingClassLoader class itself is more flexible and, while in most cases will result in the System classloader to be used, it will also work in othr managed environments that control classloading differently (OSGi, and others). The fix is minimal and the mainstream use is tested via system tests. Reviewers: Randall Hauch , Jason Gustafson --- .../connect/runtime/isolation/DelegatingClassLoader.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/isolation/DelegatingClassLoader.java b/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/isolation/DelegatingClassLoader.java index 886b415722a..83371b435d4 100644 --- a/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/isolation/DelegatingClassLoader.java +++ b/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/isolation/DelegatingClassLoader.java @@ -71,7 +71,11 @@ public class DelegatingClassLoader extends URLClassLoader { } public DelegatingClassLoader(List pluginPaths) { - this(pluginPaths, ClassLoader.getSystemClassLoader()); + // Use as parent the classloader that loaded this class. In most cases this will be the + // System classloader. But this choice here provides additional flexibility in managed + // environments that control classloading differently (OSGi, Spring and others) and don't + // depend on the System classloader to load Connect's classes. + this(pluginPaths, DelegatingClassLoader.class.getClassLoader()); } public Set> connectors() {