From 206c071029c4d2345fd1f2b07592a4e82c877b59 Mon Sep 17 00:00:00 2001 From: Marek Novotny Date: Fri, 27 Oct 2023 15:13:03 +0200 Subject: [PATCH] Add Jython version check --- gradle.properties | 3 +++ h2o-extensions/jython-cfunc/build.gradle | 10 +++++++++- .../src/main/java/org/python/core/imp.java | 5 +++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index d73c9fe5d759..e8726208087d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -67,6 +67,9 @@ jetty9MainVersion=9.4.53.v20231009 jetty9MinimalVersion=9.4.53.v20231009 servletApiVersion=3.1.0 +# Jython (Java intrapretor for Python language) +jythonVersion=2.7.3 + # Gson gsonVersion=2.9.1 diff --git a/h2o-extensions/jython-cfunc/build.gradle b/h2o-extensions/jython-cfunc/build.gradle index 34937a0d8c96..93babd3769b2 100644 --- a/h2o-extensions/jython-cfunc/build.gradle +++ b/h2o-extensions/jython-cfunc/build.gradle @@ -2,7 +2,15 @@ description = "H2O Jython Udfs" dependencies { api project(":h2o-core") - api 'org.python:jython:2.7.3' + api "org.python:jython:${jythonVersion}" + + if ("${jythonVersion}".toString() != "2.7.3") { + throw new IllegalStateException( + "This module expects Jython 2.7.3, configured version is ${jythonVersion}. " + + "Please locate org.python.core.imp class (modified from Jython 2.7.3), " + + "upgrade it to your version, port our custom changes (Marked as CUSTOM CHANGE)." + + "Once you've done that you can modify this check.") + } testImplementation project(":h2o-test-support") testRuntimeOnly project(":${defaultWebserverModule}") diff --git a/h2o-extensions/jython-cfunc/src/main/java/org/python/core/imp.java b/h2o-extensions/jython-cfunc/src/main/java/org/python/core/imp.java index c6aeacb462f7..6afec169e98e 100644 --- a/h2o-extensions/jython-cfunc/src/main/java/org/python/core/imp.java +++ b/h2o-extensions/jython-cfunc/src/main/java/org/python/core/imp.java @@ -1476,9 +1476,14 @@ private static void ensureFromList(PyObject mod, PyObject fromlist, String name) */ private static void ensureFromList(PyObject mod, PyObject fromlist, String name, boolean recursive) { + // THE ONLY CUSTOM CHANGE MADE IN THIS FILE + // The last Jython version that contains this "if" statement is 2.7.1b3. The newer versions throw an exception + // on line 1495 "Item in from list not a string". The failing type [None] is created in the library, not in H2O + // code. if (mod.__findattr__("__path__") == null) { return; } + // THE END OF THE CUSTOM CHANGE // This can happen with imports like "from . import foo" if (name.length() == 0) {