[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
1 file changed
tree: cb8f061b2663878250dc02506bd359b4d91ba27a
  1. .github/
  2. .mvn/
  3. assembly/
  4. bin/
  5. binder/
  6. build/
  7. common/
  8. conf/
  9. connector/
  10. core/
  11. data/
  12. dev/
  13. docs/
  14. examples/
  15. graphx/
  16. hadoop-cloud/
  17. launcher/
  18. licenses/
  19. licenses-binary/
  20. mllib/
  21. mllib-local/
  22. project/
  23. python/
  24. R/
  25. repl/
  26. resource-managers/
  27. sbin/
  28. sql/
  29. streaming/
  30. tools/
  31. udf/
  32. ui-test/
  33. .asf.yaml
  34. .gitattributes
  35. .gitignore
  36. .nojekyll
  37. .pre-commit-config.yaml
  38. .sbtopts
  39. AGENTS.md
  40. CONTRIBUTING.md
  41. LICENSE
  42. LICENSE-binary
  43. NOTICE
  44. NOTICE-binary
  45. pom.xml
  46. pyproject.toml
  47. README.md
  48. scalastyle-config.xml
  49. SECURITY.md
README.md

Apache Spark

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.

License Maven Central Java GitHub Actions Build PySpark Coverage PyPI Downloads

Online Documentation

You can find the latest Spark documentation, including a programming guide, on the project web page. This README file only contains basic setup instructions.

Build Pipeline Status

BranchStatus
masterGitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
branch-4.xGitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
branch-4.3GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
branch-4.2GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
branch-4.1GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
branch-4.0GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
GitHub Actions Build
branch-3.5GitHub Actions Build
GitHub Actions Build
GitHub Actions Build

Building Spark

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”.

Interactive Scala Shell

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()

Interactive Python Shell

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()

Example Programs

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.

Running Tests

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

A Note About Hadoop Versions

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.

Configuration

Please refer to the Configuration Guide in the online documentation for an overview on how to configure Spark.

Contributing

Please review the Contribution to Spark guide for information on how to get started contributing to the project.