Skip to content

[SPARK-58867][BUILD] Add Scala initialization checks to build - #58112

Open
zhengruifeng wants to merge 2 commits into
apache:masterfrom
zhengruifeng:SPARK-58867-scala-checkinit
Open

[SPARK-58867][BUILD] Add Scala initialization checks to build#58112
zhengruifeng wants to merge 2 commits into
apache:masterfrom
zhengruifeng:SPARK-58867-scala-checkinit

Conversation

@zhengruifeng

@zhengruifeng zhengruifeng commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This PR adds -Xcheckinit to Spark's Scala compiler options for both SBT and Maven builds. It
also 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 PythonArrowInput
had 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 -Xcheckinit to add runtime checks in generated bytecode and identify accesses
to 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 and
asserts that -Xcheckinit detects the eager read as UninitializedFieldError.

Not run.

git diff --check

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

Generated-by: OpenAI GPT-5 Codex

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