Skip to content

[SPARK-56043][SQL] Wrap NullPointerException from Avro 1.12.x ParseContext.resolve() in SchemaParseException#54876

Closed
jerrypeng wants to merge 3 commits intoapache:masterfrom
jerrypeng:SPARK-56043
Closed

[SPARK-56043][SQL] Wrap NullPointerException from Avro 1.12.x ParseContext.resolve() in SchemaParseException#54876
jerrypeng wants to merge 3 commits intoapache:masterfrom
jerrypeng:SPARK-56043

Conversation

@jerrypeng
Copy link
Contributor

@jerrypeng jerrypeng commented Mar 18, 2026

What changes were proposed in this pull request?

Add AvroUtils.parseAvroSchema() that wraps Schema.Parser().parse() and catches NullPointerException, re-throwing it as SchemaParseException. This lets the existing parseMode-based error handling (FAILFAST → MALFORMED_AVRO_MESSAGE, PERMISSIVE → null row) work correctly. All call sites (AvroDataToCatalyst, CatalystDataToAvro, SchemaOfAvro, AvroOptions, AvroOutputWriterFactory, and the schema registry variants) are updated to use it.

Why are the changes needed?

After the Avro 1.11.3 → 1.12.0 upgrade (SPARK-49014), Schema.Parser().parse() can throw NullPointerException from ParseContext.resolve() for certain invalid user-provided schemas. In Avro 1.11.x, the same schemas threw SchemaParseException, which was caught by the existing NonFatal(e) handler in AvroDataToCatalyst.nullSafeEval and reported as MALFORMED_AVRO_MESSAGE. The NPE bypasses nothing — it's still NonFatal — but it surfaces as an unclassified internal error rather than a schema parse error because it was never expected from schema parsing.

Does this PR introduce any user-facing change?

no

How was this patch tested?

tests added

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

yes

Generated-by: claude

@HyukjinKwon HyukjinKwon changed the title [SPARK-56043] Wrap NullPointerException from Avro 1.12.x ParseContext.resolve() in SchemaParseException [SPARK-56043][SQL] Wrap NullPointerException from Avro 1.12.x ParseContext.resolve() in SchemaParseException Mar 18, 2026
@HyukjinKwon
Copy link
Member

HyukjinKwon commented Mar 18, 2026

Merged to master.

@HyukjinKwon
Copy link
Member

@jerrypeng do you want to make backport PRs? It has some minor conflicts.

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.

3 participants