[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 the other two pass none. 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 they fail before Arrow allocates, get the same options, so they do not break the same way if that code path changes. 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 <max.gekk@gmail.com> Co-authored-by: t <t@example.com> Signed-off-by: Max Gekk <max.gekk@gmail.com> skip-checks: true
Spark is a unified analytics engine for large-scale data processing. It provides high-level APIs in Scala, Java, Python, and R (Deprecated), and an optimized engine that supports general computation graphs for data analysis. It also supports a rich set of higher-level tools including Spark SQL for SQL and DataFrames, pandas API on Spark for pandas workloads, MLlib for machine learning, GraphX for graph processing, and Structured Streaming for stream processing.
You can find the latest Spark documentation, including a programming guide, on the project web page. This README file only contains basic setup instructions.
| Branch | Status |
|---|---|
| master | |
| branch-4.x | |
| branch-4.3 | |
| branch-4.2 | |
| branch-4.1 | |
| branch-4.0 | |
| branch-3.5 | |
Spark is built using Apache Maven. To build Spark and its example programs, run:
./build/mvn -DskipTests clean package
(You do not need to do this if you downloaded a pre-built package.)
More detailed documentation is available from the project site, at “Building Spark”.
For general development tips, including info on developing Spark using an IDE, see “Useful Developer Tools”.
The easiest way to start using Spark is through the Scala shell:
./bin/spark-shell
Try the following command, which should return 1,000,000,000:
scala> spark.range(1000 * 1000 * 1000).count()
Alternatively, if you prefer Python, you can use the Python shell:
./bin/pyspark
And run the following command, which should also return 1,000,000,000:
>>> spark.range(1000 * 1000 * 1000).count()
Spark also comes with several sample programs in the examples directory. To run one of them, use ./bin/run-example <class> [params]. For example:
./bin/run-example SparkPi
will run the Pi example locally.
You can set the MASTER environment variable when running examples to submit examples to a cluster. This can be spark:// URL, “yarn” to run on YARN, and “local” to run locally with one thread, or “local[N]” to run locally with N threads. You can also use an abbreviated class name if the class is in the examples package. For instance:
MASTER=spark://host:7077 ./bin/run-example SparkPi
Many of the example programs print usage help if no params are given.
Testing first requires building Spark. Once Spark is built, tests can be run using:
./dev/run-tests
Please see the guidance on how to run tests for a module, or individual tests.
There is also a Kubernetes integration test, see resource-managers/kubernetes/integration-tests/README.md
Spark uses the Hadoop core library to talk to HDFS and other Hadoop-supported storage systems. Because the protocols have changed in different versions of Hadoop, you must build Spark against the same version that your cluster runs.
Please refer to the build documentation at “Specifying the Hadoop Version and Enabling YARN” for detailed guidance on building for a particular distribution of Hadoop, including building for particular Hive and Hive Thriftserver distributions.
Please refer to the Configuration Guide in the online documentation for an overview on how to configure Spark.
Please review the Contribution to Spark guide for information on how to get started contributing to the project.