This is an automated email from the ASF dual-hosted git repository. dianfu pushed a commit to branch release-1.11 in repository https://gitbox.apache.org/repos/asf/flink.git
The following commit(s) were added to refs/heads/release-1.11 by this push: new fb3fc1e [FLINK-17945][python] Improve the error message when instantiating non-existing Java class fb3fc1e is described below commit fb3fc1ef82df6b73174c5aff28d54ab4eb96b094 Author: Dian Fu <dia...@apache.org> AuthorDate: Wed Jun 3 22:42:19 2020 +0800 [FLINK-17945][python] Improve the error message when instantiating non-existing Java class This closes #12469. --- flink-python/pyflink/java_gateway.py | 3 ++- flink-python/pyflink/util/exceptions.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/flink-python/pyflink/java_gateway.py b/flink-python/pyflink/java_gateway.py index 0f8b904..6bce4e1 100644 --- a/flink-python/pyflink/java_gateway.py +++ b/flink-python/pyflink/java_gateway.py @@ -28,7 +28,7 @@ from threading import RLock from py4j.java_gateway import (java_import, logger, JavaGateway, GatewayParameters, CallbackServerParameters) from pyflink.pyflink_gateway_server import launch_gateway_server_process -from pyflink.util.exceptions import install_exception_handler +from pyflink.util.exceptions import install_exception_handler, install_py4j_hooks _gateway = None _lock = RLock() @@ -69,6 +69,7 @@ def get_gateway(): # import the flink view import_flink_view(_gateway) install_exception_handler() + install_py4j_hooks() _gateway.entry_point.put("PythonFunctionFactory", PythonFunctionFactory()) _gateway.entry_point.put("Watchdog", Watchdog()) return _gateway diff --git a/flink-python/pyflink/util/exceptions.py b/flink-python/pyflink/util/exceptions.py index 2a28936..c3ee65e 100644 --- a/flink-python/pyflink/util/exceptions.py +++ b/flink-python/pyflink/util/exceptions.py @@ -172,3 +172,15 @@ def install_exception_handler(): patched = capture_java_exception(original) # only patch the one used in py4j.java_gateway (call Java API) py4j.java_gateway.get_return_value = patched + + +def install_py4j_hooks(): + """ + Hook the classes such as JavaPackage, etc of Py4j to improve the exception message. + """ + def wrapped_call(self, *args, **kwargs): + raise TypeError( + "Could not found the Java class '%s'. The Java dependencies could be specified via " + "command line argument '--jarfile' or the config option 'pipeline.jars'" % self._fqn) + + setattr(py4j.java_gateway.JavaPackage, '__call__', wrapped_call)