You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by tr...@apache.org on 2019/06/20 17:21:04 UTC

[flink] 02/03: [hotfix] Convert ClassNotFoundException to FlinkException if the type implementing class is not found in InstantiationUtil.instantiate

This is an automated email from the ASF dual-hosted git repository.

trohrmann pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git

commit 39e77bafbc73e20e1c7b422e413b8fe58b5047e5
Author: Andrey Zagrebin <az...@gmail.com>
AuthorDate: Mon Jun 17 10:12:20 2019 +0200

    [hotfix] Convert ClassNotFoundException to FlinkException if the type implementing class is not found in InstantiationUtil.instantiate
---
 .../org/apache/flink/util/InstantiationUtil.java   | 22 ++++++++++++++++------
 .../HighAvailabilityServicesUtils.java             | 18 ++++--------------
 2 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/flink-core/src/main/java/org/apache/flink/util/InstantiationUtil.java b/flink-core/src/main/java/org/apache/flink/util/InstantiationUtil.java
index 6442891..d98ba93 100644
--- a/flink-core/src/main/java/org/apache/flink/util/InstantiationUtil.java
+++ b/flink-core/src/main/java/org/apache/flink/util/InstantiationUtil.java
@@ -338,13 +338,23 @@ public final class InstantiationUtil {
 	 * @param classLoader to use for loading the class
 	 * @param <T> type of the instantiated class
 	 * @return Instance of the given class name
-	 * @throws ClassNotFoundException if the class could not be found
+	 * @throws FlinkException if the class could not be found
 	 */
-	public static <T> T instantiate(final String className, final Class<T> targetType, final ClassLoader classLoader) throws ClassNotFoundException {
-		final Class<? extends T> clazz = Class.forName(
-			className,
-			false,
-			classLoader).asSubclass(targetType);
+	public static <T> T instantiate(final String className, final Class<T> targetType, final ClassLoader classLoader) throws FlinkException {
+		final Class<? extends T> clazz;
+		try {
+			clazz = Class.forName(
+				className,
+				false,
+				classLoader).asSubclass(targetType);
+		} catch (ClassNotFoundException e) {
+			throw new FlinkException(
+				String.format(
+					"Could not instantiate class '%s' of type '%s'. Please make sure that this class is on your class path.",
+					className,
+					targetType.getName()),
+				e);
+		}
 
 		return instantiate(clazz);
 	}
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/highavailability/HighAvailabilityServicesUtils.java b/flink-runtime/src/main/java/org/apache/flink/runtime/highavailability/HighAvailabilityServicesUtils.java
index 1263dc1..2cdd501 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/highavailability/HighAvailabilityServicesUtils.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/highavailability/HighAvailabilityServicesUtils.java
@@ -164,20 +164,10 @@ public class HighAvailabilityServicesUtils {
 		final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
 		final String haServicesClassName = config.getString(HighAvailabilityOptions.HA_MODE);
 
-		final HighAvailabilityServicesFactory highAvailabilityServicesFactory;
-
-		try {
-			highAvailabilityServicesFactory = InstantiationUtil.instantiate(
-				haServicesClassName,
-				HighAvailabilityServicesFactory.class,
-				classLoader);
-		} catch (Exception e) {
-			throw new FlinkException(
-				String.format(
-					"Could not instantiate the HighAvailabilityServicesFactory '%s'. Please make sure that this class is on your class path.",
-					haServicesClassName),
-				e);
-		}
+		final HighAvailabilityServicesFactory highAvailabilityServicesFactory = InstantiationUtil.instantiate(
+			haServicesClassName,
+			HighAvailabilityServicesFactory.class,
+			classLoader);
 
 		try {
 			return highAvailabilityServicesFactory.createHAServices(config, executor);