You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2021/07/01 08:34:38 UTC

[GitHub] [kafka] showuon commented on a change in pull request #10938: Fix StringSerializer could not be found when it not in ContextClassLoader

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



##########
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:
       How could you confirm the exception thrown is from `non-kafkaClassLoader`?




-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org