Skip to content

[SPARK-57519][CORE] Fix NoSuchElementException in ErrorClassesJsonReader.isValidErrorClass for error classes without sub-classes#56583

Open
LuciferYang wants to merge 1 commit into
apache:masterfrom
LuciferYang:fix-error-class-validation
Open

[SPARK-57519][CORE] Fix NoSuchElementException in ErrorClassesJsonReader.isValidErrorClass for error classes without sub-classes#56583
LuciferYang wants to merge 1 commit into
apache:masterfrom
LuciferYang:fix-error-class-validation

Conversation

@LuciferYang

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

ErrorClassesJsonReader.isValidErrorClass checks a two-part error class name (MAIN.SUB) with info.subClass.get.contains(subClass). When the main class has no sub-classes, info.subClass is None, so .get throws NoSuchElementException.

This PR changes that to info.subClass.exists(_.contains(subClass)), which returns false in that case instead of throwing, and adds a test to SparkThrowableSuite.

Why are the changes needed?

isValidErrorClass is meant to return a boolean, but it threw for this input. It is reachable from user SQL: SQL scripting handler declarations validate two-part condition names through SparkThrowableHelper.isValidErrorClass (in AstBuilder), and so does RAISE_ERROR. As a result a name like DIVIDE_BY_ZERO.X (a real top-level error class with no sub-classes) surfaced an internal NoSuchElementException instead of the intended "condition not found" error.

Does this PR introduce any user-facing change?

Yes. Validating a two-part error condition name whose main class has no sub-classes no longer throws NoSuchElementException; it returns false, so the caller can report the proper error. Inputs that already returned without throwing are unaffected.

How was this patch tested?

Added a unit test in SparkThrowableSuite that covers a main class without sub-classes, a main class with sub-classes (valid and unknown sub-class), unknown main classes, and malformed names. build/sbt 'core/testOnly *SparkThrowableSuite' passes (34 tests).

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

Generated-by: Claude Code (Opus 4.8)

…der.isValidErrorClass for error classes without sub-classes

`isValidErrorClass` called `info.subClass.get` on the sub-class `Option`,
which threw `NoSuchElementException` when a main error class exists but
defines no sub-classes and is queried with a two-part name (`MAIN.SUB`).
This is reachable from user SQL: SQL scripting handler declarations validate
two-part condition names via `SparkThrowableHelper.isValidErrorClass`, so the
internal exception leaked instead of the intended `conditionNotFound` error.

Replace `info.subClass.get.contains(subClass)` with
`info.subClass.exists(_.contains(subClass))`, which returns `false` when no
sub-classes are defined. Add a regression test in `SparkThrowableSuite`.
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