[SPARK-58867][BUILD] Add Scala initialization checks to build - #58112
Open
zhengruifeng wants to merge 2 commits into
Open
[SPARK-58867][BUILD] Add Scala initialization checks to build#58112zhengruifeng wants to merge 2 commits into
zhengruifeng wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
This PR adds
-Xcheckinitto Spark's Scala compiler options for both SBT and Maven builds. Italso adds a small test that deliberately triggers this class of initialization-order bug and
asserts that execution fails with
UninitializedFieldError.Why are the changes needed?
This is motivated by #54068, where
PythonArrowInputhad an initialization-order issue: an eager trait initializer could read subclass fields before
those fields had been initialized.
The Scala official FAQ describes this class of issue in "Why is my abstract or overridden val
null?": https://docs.scala-lang.org/tutorials/FAQ/initialization-order.html. For Scala 2,
the FAQ recommends
-Xcheckinitto add runtime checks in generated bytecode and identify accessesto uninitialized fields.
Adding this option helps catch problematic initialization-order patterns, such as eager trait
initializers reading subclass fields before those fields have been initialized.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
Added
ScalaInitializationCheckSuite, which constructs a deliberately broken trait/class pair andasserts that
-Xcheckinitdetects the eager read asUninitializedFieldError.Not run.
git diff --checkWas this patch authored or co-authored using generative AI tooling?
Generated-by: OpenAI GPT-5 Codex