Skip to content

[SPARK-56447][SHELL] Fix spark-shell REPL classpath initialization error#55305

Draft
jiwen624 wants to merge 1 commit intoapache:masterfrom
jiwen624:SPARK-56447-spark-shell-repl-classpath
Draft

[SPARK-56447][SHELL] Fix spark-shell REPL classpath initialization error#55305
jiwen624 wants to merge 1 commit intoapache:masterfrom
jiwen624:SPARK-56447-spark-shell-repl-classpath

Conversation

@jiwen624
Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

In Main.doMain, prepend java.class.path to the -classpath argument passed to the REPL's GenericRunnerSettings:

Why are the changes needed?

$SPARK_HOME/bin/spark-shell fails with:

Failed to initialize compiler: object scala in compiler mirror not found.
** Note that as of 2.8 scala does not assume use of the java classpath.
** For the old behavior pass -usejavacp to scala, or if using a Settings
** object programmatically, settings.usejavacp.value = true.
Exception in thread "main" java.lang.NullPointerException: Cannot throw exception because "null" is null
        at scala.tools.nsc.CompilationUnits$CompilationUnit.<init>(CompilationUnits.scala:43)
        at scala.tools.nsc.CompilationUnits$CompilationUnit.<init>(CompilationUnits.scala:44)
        at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.compile(IMain.scala:734) 

This works in previous versions.
bin/spark-shell has passed -Dscala.usejavacp=true since SPARK-4161 to address exactly this behaviour. The mechanism is broken after SPARK-52587 which initializes the compiler before the classpath is set. The fix makes doMain explicitly include java.class.path in the -classpath argument, restoring correct behaviour regardless of how SparkILoop is constructed.

Does this PR introduce any user-facing change?

Yes. spark-shell was broken with a compiler initialization error. This PR fixes it so spark-shell starts and evaluates
expressions correctly again.

How was this patch tested?

Added a unit test in ReplSuite that calls Main.doMain with Array.empty (no explicit -classpath argument) and verifies the output. This test fails on the unfixed code and passes after the fix.

Was this patch authored or co-authored using generative AI tooling?

No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant