gharris1727 commented on code in PR #14304:
URL: https://github.com/apache/kafka/pull/14304#discussion_r1316362502


##########
clients/src/main/java/org/apache/kafka/common/utils/Utils.java:
##########
@@ -1519,6 +1537,32 @@ public static String[] enumOptions(Class<? extends 
Enum<?>> enumClass) {
                 .toArray(String[]::new);
     }
 
+    /**
+     * Ensure that the class is concrete (i.e., not abstract). If it is, throw 
a {@link ConfigException}
+     * with a friendly error message suggesting a list of concrete child 
subclasses (if any are known).
+     * @param cls the class to check; may not be null
+     * @param name the name of the type of class to use in the error message; 
e.g., "Transform",
+     *             "Interceptor", or even just "Class"; may be null
+     * @throws ConfigException if the class is not concrete
+     */
+    public static void ensureConcrete(Class<?> cls, String name) {
+        Objects.requireNonNull(cls);
+        if (isBlank(name))
+            name = "Class";
+        if (Modifier.isAbstract(cls.getModifiers())) {
+            String childClassNames = Stream.of(cls.getClasses())
+                    .filter(cls::isAssignableFrom)
+                    .filter(c -> !Modifier.isAbstract(c.getModifiers()))
+                    .filter(c -> Modifier.isPublic(c.getModifiers()))
+                    .map(Class::getName)
+                    .collect(Collectors.joining(", "));
+            String message = Utils.isBlank(childClassNames) ?
+                    name + " is abstract and cannot be created." :
+                    name + " is abstract and cannot be created. Did you mean " 
+ childClassNames + "?";
+            throw new ConfigException(name, cls.getName(), message);

Review Comment:
   I like this simplification, and it makes sense to generalize the error 
message as part of promoting this to the Utils class. `parseForValidate` will 
still attribute the error to the correct key/value.



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