You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by di...@apache.org on 2020/06/04 02:18:03 UTC

[flink] branch release-1.10 updated: [FLINK-17945][python] Improve the error message when instantiating non-existing Java class

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

dianfu pushed a commit to branch release-1.10
in repository https://gitbox.apache.org/repos/asf/flink.git


The following commit(s) were added to refs/heads/release-1.10 by this push:
     new dddd0f0  [FLINK-17945][python] Improve the error message when instantiating non-existing Java class
dddd0f0 is described below

commit dddd0f0e6341f0da053f2c1ace05b7b4fad527a2
Author: Dian Fu <di...@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 06ae14f..5339b66 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, JavaGateway, GatewayParameters
 from pyflink.find_flink_home import _find_flink_home
-from pyflink.util.exceptions import install_exception_handler
+from pyflink.util.exceptions import install_exception_handler, install_py4j_hooks
 
 _gateway = None
 _lock = RLock()
@@ -59,6 +59,7 @@ def get_gateway():
             # import the flink view
             import_flink_view(_gateway)
             install_exception_handler()
+            install_py4j_hooks()
     return _gateway
 
 
diff --git a/flink-python/pyflink/util/exceptions.py b/flink-python/pyflink/util/exceptions.py
index 2a28936..5c742ae 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'" % self._fqn)
+
+    setattr(py4j.java_gateway.JavaPackage, '__call__', wrapped_call)