eshizhan commented on a change in pull request #10938:
URL: https://github.com/apache/kafka/pull/10938#discussion_r662351754



##########
File path: clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java
##########
@@ -725,14 +725,21 @@ else if (value instanceof String)
                     if (value instanceof Class)
                         return value;
                     else if (value instanceof String) {
-                        ClassLoader contextOrKafkaClassLoader = 
Utils.getContextOrKafkaClassLoader();
-                        // Use loadClass here instead of Class.forName because 
the name we use here may be an alias
-                        // and not match the name of the class that gets 
loaded. If that happens, Class.forName can
-                        // throw an exception.
-                        Class<?> klass = 
contextOrKafkaClassLoader.loadClass(trimmed);
-                        // Invoke forName here with the true name of the 
requested class to cause class
-                        // initialization to take place.
-                        return Class.forName(klass.getName(), true, 
contextOrKafkaClassLoader);
+                        try {
+                            ClassLoader contextOrKafkaClassLoader = 
Utils.getContextOrKafkaClassLoader();
+                            // Use loadClass here instead of Class.forName 
because the name we use here may be an alias
+                            // and not match the name of the class that gets 
loaded. If that happens, Class.forName can
+                            // throw an exception.
+                            Class<?> klass = 
contextOrKafkaClassLoader.loadClass(trimmed);
+                            // Invoke forName here with the true name of the 
requested class to cause class
+                            // initialization to take place.
+                            return Class.forName(klass.getName(), true, 
contextOrKafkaClassLoader);
+                        } catch (ClassNotFoundException e) {
+                            // load class from kafkaClassLoader when it not in 
ContextClassLoader
+                            ClassLoader kafkaClassLoader = 
Utils.getKafkaClassLoader();

Review comment:
       It's use `ContextClassLoader` first in 
`Utils.getContextOrKafkaClassLoader`. And if `contextOrKafkaClassLoader` is 
`KafkaClassLoader`, it will be load class twice with failed. Whatever happens, 
an exception will thrown.




-- 
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


Reply via email to