Skip to content

[SPARK-55747][SQL] Fix NPE when accessing elements from an array that is null#54546

Closed
stevomitric wants to merge 3 commits intoapache:masterfrom
stevomitric:stevomitric/fix-npe-codegen
Closed

[SPARK-55747][SQL] Fix NPE when accessing elements from an array that is null#54546
stevomitric wants to merge 3 commits intoapache:masterfrom
stevomitric:stevomitric/fix-npe-codegen

Conversation

@stevomitric
Copy link
Contributor

What changes were proposed in this pull request?

The GetArrayItem expression incorrectly computed nullable = false when indexing into arrays with containsNull = false (e.g., from split()), even when the array itself could be null. This caused codegen to skip null checks, leading to NPE on array.numElements() during bounds checking.

Why are the changes needed?

To resolve NPE within spark engine.

Does this PR introduce any user-facing change?

No

How was this patch tested?

Tests in this PR.

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

No

@stevomitric
Copy link
Contributor Author

cc @cloud-fan to PTAL

@stevomitric stevomitric changed the title [SPARK-55747] Fix NPE when accessing elements from an array that is null [SPARK-55747][SQL] Fix NPE when accessing elements from an array that is null Feb 27, 2026
Co-authored-by: YangJie <yangjie01@baidu.com>
@cloud-fan
Copy link
Contributor

cloud-fan commented Mar 1, 2026

the OOM issue is unrelated, thanks, merging to master/4.1!

@cloud-fan cloud-fan closed this in c0e367a Mar 1, 2026
cloud-fan added a commit that referenced this pull request Mar 1, 2026
… is null

### What changes were proposed in this pull request?
The `GetArrayItem` expression incorrectly computed `nullable = false` when indexing into arrays with `containsNull = false` (e.g., from split()), even when the array itself could be null. This caused codegen to skip null checks, leading to NPE on `array.numElements()` during bounds checking.

### Why are the changes needed?
To resolve NPE within spark engine.

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?
Tests in this PR.

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

Closes #54546 from stevomitric/stevomitric/fix-npe-codegen.

Lead-authored-by: Wenchen Fan <cloud0fan@gmail.com>
Co-authored-by: Stevo Mitric <stevo.mitric@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
(cherry picked from commit c0e367a)
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
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