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 2022/06/17 14:16:30 UTC

[GitHub] [kafka] ijuma commented on a diff in pull request #12230: MINOR: Catch InvocationTargetException explicitly and propagate underlying cause

ijuma commented on code in PR #12230:
URL: https://github.com/apache/kafka/pull/12230#discussion_r900163290


##########
clients/src/main/java/org/apache/kafka/common/utils/Utils.java:
##########
@@ -463,8 +463,7 @@ public static <T> T newParameterizedInstance(String className, Object... params)
             throw new ClassNotFoundException(String.format("Unable to access " +
                 "constructor of %s", className), e);
         } catch (InvocationTargetException e) {
-            throw new ClassNotFoundException(String.format("Unable to invoke " +
-                "constructor of %s", className), e);
+            throw new KafkaException(String.format("The constructor of %s threw an exception", className), e.getCause());

Review Comment:
   Have we checked that changing this exception doesn't cause an issue?



##########
clients/src/test/java/org/apache/kafka/common/KafkaFutureTest.java:
##########
@@ -637,7 +637,12 @@ public void testLeakCompletableFuture() throws NoSuchMethodException, Invocation
 
             // Check the CF from a minimal CompletionStage doesn't cause completion of the original KafkaFuture
             Method minimal = CompletableFuture.class.getDeclaredMethod("minimalCompletionStage");
-            CompletionStage<String> cs = (CompletionStage<String>) minimal.invoke(comfut);
+            CompletionStage<String> cs = null;
+            try {
+                cs = (CompletionStage<String>) minimal.invoke(comfut);
+            } catch (InvocationTargetException e) {
+                throw e.getCause();
+            }

Review Comment:
   Maybe we should have a helper `invoke` method since we do this many times in this test?



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