This is an automated email from the ASF dual-hosted git repository.
MaxGekk pushed a commit to branch branch-4.x
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-4.x by this push:
new 22e0f012bf40 [SPARK-61280][PYTHON][TEST] Start the in-process UDF
probe JVMs with Spark's module options
22e0f012bf40 is described below
commit 22e0f012bf40b7572507927845ddec98b80aeedb
Author: Max Gekk <[email protected]>
AuthorDate: Tue Nov 10 12:20:21 2026 +0100
[SPARK-61280][PYTHON][TEST] Start the in-process UDF probe JVMs with
Spark's module options
### What changes were proposed in this pull request?
Four tests in `python/pyspark/sql/tests/test_inprocess_udf.py` start a
fresh JVM with a hand-written `java` command line:
`test_missing_cdi_dependency_fails_plugin_startup`,
`test_missing_jep_has_an_initialization_hint`,
`test_fresh_jvm_retries_configuration_without_spark_home` and
`test_failed_bootstrap_preserves_message_and_freezes_site_packages`. Two of
them pass a hand-picked subset of Spark's JVM options (two `--add-opens` and
`-Dio.netty.tryReflectionSetAccessible=true`), and th [...]
This PR adds a helper, `_java_command(jvm, java_home)`, which returns this
test's `java` followed by `JavaModuleOptions.defaultModuleOptionArray()`, the
options Spark's own launcher passes to every JVM it starts. All four probes now
build their command line from it, so a probe JVM starts the way Spark's JVMs do
on every Java version.
### Why are the changes needed?
On Java 25, `test_missing_jep_has_an_initialization_hint` and
`test_fresh_jvm_retries_configuration_without_spark_home` fail. The fresh JVM
each one starts exits 1 with:
```
java.lang.ClassCastException: class io.netty.buffer.PooledDirectByteBuf
cannot be cast to class io.netty.buffer.PooledUnsafeDirectByteBuf
```
On Java 25+, Netty 4.2 turns off its use of `Unsafe` unless the JVM runs
with `--sun-misc-unsafe-memory-access=allow`. Arrow's
`PooledByteBufAllocatorL$InnerAllocator.newDirectBufferL` always casts the
buffer Netty returns to `PooledUnsafeDirectByteBuf`, so without `Unsafe` the
first Arrow allocation throws. Both probes allocate one: one through
`InProcessArrowBridge.verifyDependencies`, the other through
`InterpreterSession.register`.
Spark's own JVMs get that option from `JavaModuleOptions`, which added it
in SPARK-56955. The probes copied part of that list by hand before it was
added, so they never got it. Taking the list itself fixes the failure and keeps
the probes in step with the next option Spark adds. It also gives the probes
that load jep's native library `--enable-native-access=ALL-UNNAMED`, which
avoids the restricted-method warning on Java 24+. And the two probes that pass
a bare `java` today, because t [...]
CI has not caught it because the tests are skipped wherever jep is missing.
The Java 25 build uses the `python-311` image, which has no jep. A Java 25
build on the `python-312` image, which installs jep, fails both tests. Running
these tests on Java 25 with jep in CI would be a separate change to the test
images.
### Does this PR introduce _any_ user-facing change?
No. Test code only.
### How was this patch tested?
- Reproduced the failure outside Spark with a one-file Java program that
calls `new RootAllocator().buffer(64)` against the Arrow 19.0.0 and Netty
4.2.20 jars Spark uses:
- On JDK 25 with the probes' old options, it throws the same
`ClassCastException` and exits 1.
- On JDK 25 with `--sun-misc-unsafe-memory-access=allow` added, which
`JavaModuleOptions` includes, the buffer is allocated and it exits 0.
- On JDK 21 it exits 0 either way. `JavaModuleOptions` starts with
`-XX:+IgnoreUnrecognizedVMOptions`, so Java 21 accepts the newer options, as it
does for Spark's own JVMs.
- The two tests fail in a Java 25 build that installs jep (the `python-312`
image).
- `ruff check` and `ruff format --check` pass on the file.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 5.5)
Closes #60257 from MaxGekk/SPARK-61280-inprocess-unsafe.
Lead-authored-by: Max Gekk <[email protected]>
Co-authored-by: t <[email protected]>
Signed-off-by: Max Gekk <[email protected]>
(cherry picked from commit 098b0645bf98de2bb3923d37aff86a5435743a7f)
Signed-off-by: Max Gekk <[email protected]>
skip-checks: true
---
python/pyspark/sql/tests/test_inprocess_udf.py | 35 ++++++++++++++++----------
1 file changed, 22 insertions(+), 13 deletions(-)
diff --git a/python/pyspark/sql/tests/test_inprocess_udf.py
b/python/pyspark/sql/tests/test_inprocess_udf.py
index fe6ef4bb1460..b12f24d583d5 100644
--- a/python/pyspark/sql/tests/test_inprocess_udf.py
+++ b/python/pyspark/sql/tests/test_inprocess_udf.py
@@ -303,6 +303,21 @@ class InProcessUDFTests(ReusedSQLTestCase):
self.spark.range(1).select(inprocess_udf("boolean")(flags)("id")).first()[0]
)
+ @staticmethod
+ def _java_command(jvm, java_home):
+ """
+ The start of a command line for a fresh probe JVM: this test's java
and the module
+ options Spark's own launcher passes (JavaModuleOptions), so a probe
gets the same module
+ options as Spark's JVMs on every Java version, e.g. with Unsafe
allowed for Netty on
+ Java 25+. Only the module options are shared: the other options
python/run-tests.py
+ gives the test JVM, such as java.io.tmpdir, are not.
+
+ The options start with -XX:+IgnoreUnrecognizedVMOptions, which also
applies to the
+ options a probe appends, so a misspelled -XX option does not fail the
launch.
+ """
+ options =
jvm.org.apache.spark.launcher.JavaModuleOptions.defaultModuleOptions()
+ return [str(Path(java_home) / "bin" / "java")] + options.split(" ")
+
def test_missing_cdi_dependency_fails_plugin_startup(self):
import subprocess
@@ -341,7 +356,7 @@ class MissingCdiProbe {
source_file = Path(directory) / "MissingCdiProbe.java"
source_file.write_text(source)
result = subprocess.run(
- [str(Path(java_home) / "bin" / "java"), "-cp", classpath,
str(source_file)],
+ self._java_command(jvm, java_home) + ["-cp", classpath,
str(source_file)],
capture_output=True,
text=True,
timeout=90,
@@ -393,11 +408,8 @@ class MissingJepProbe {
source_file = Path(directory) / "MissingJepProbe.java"
source_file.write_text(source)
result = subprocess.run(
- [
- str(Path(java_home) / "bin" / "java"),
- "--add-opens=java.base/java.nio=ALL-UNNAMED",
- "--add-opens=java.base/sun.nio.ch=ALL-UNNAMED",
- "-Dio.netty.tryReflectionSetAccessible=true",
+ self._java_command(jvm, java_home)
+ + [
"-cp",
classpath,
str(source_file),
@@ -522,11 +534,8 @@ class BootstrapProbe {
import sys
result = subprocess.run(
- [
- str(Path(java_home) / "bin" / "java"),
- "--add-opens=java.base/java.nio=ALL-UNNAMED",
- "--add-opens=java.base/sun.nio.ch=ALL-UNNAMED",
- "-Dio.netty.tryReflectionSetAccessible=true",
+ self._java_command(jvm, java_home)
+ + [
f"-Djava.library.path={self.jep_dir}",
"--class-path",
classpath,
@@ -602,8 +611,8 @@ class BootstrapFailureProbe {
[str(self.python_source), str(Path(py4j.__file__).parents[1])]
)
result = subprocess.run(
- [
- str(Path(java_home) / "bin" / "java"),
+ self._java_command(jvm, java_home)
+ + [
f"-Djava.library.path={self.jep_dir}",
"--class-path",
classpath,
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]