Skip to content

[SEDONA-752] fix: NullPointerException from deep traversal beyond GeoJSON geometry level#2959

Merged
jiayuasu merged 1 commit into
apache:masterfrom
prantogg:pranav/bugfix/geojson-npe-deep-traversal
May 17, 2026
Merged

[SEDONA-752] fix: NullPointerException from deep traversal beyond GeoJSON geometry level#2959
jiayuasu merged 1 commit into
apache:masterfrom
prantogg:pranav/bugfix/geojson-npe-deep-traversal

Conversation

@prantogg
Copy link
Copy Markdown
Contributor

@prantogg prantogg commented May 16, 2026

Did you read the Contributor Guide?

Is this PR related to a ticket?

  • Yes, and the PR name follows the format [SEDONA-XXX] my subject.
  • Yes, and the PR name follows the format [GH-XXX] my subject. Closes #<issue_number>

What changes were proposed in this PR?

The GeoJSON reader's convertGeoJsonToGeometry and updateGeometrySchema methods were recursing into all nested StructType fields unconditionally. When a GeoJSON feature had nested struct properties (e.g., properties.prop1.nested_field), the traversal would descend into those property-level structs looking for a "geometry" field to convert. If any such struct happened to have fields that didn't match expected geometry patterns, this caused a NullPointerException.

This PR fixes the issue by:

  • Adding a hasGeometryField helper that detects whether the current struct level contains a "geometry" field
  • Once a geometry-level struct is found, only the "geometry" field is converted; sibling struct/array fields are passed through as-is without further recursion
  • Adding null-safety checks throughout the traversal to prevent NPE on null fields
  • Updating updateGeometrySchema with the same bounded-recursion logic so schema updates stop at the first geometry level

How was this patch tested?

  • Updated the geojson_feature-collection.json test fixture to include nested struct properties (with multiple levels of nesting) that previously triggered the NPE
  • Added a unit test updateGeometrySchema should update first geometry struct only that verifies schema traversal stops at the first geometry level and does not modify deeper "geometry" fields in property structs
  • Existing GeoJSON read/write tests continue to pass

Did this PR include necessary documentation updates?

  • No, this PR does not affect any public API so no need to change the documentation.

@prantogg prantogg changed the title fix: NullPointerException from deep traversal beyond GeoJSON geometry level [SEDONA-752] fix: NullPointerException from deep traversal beyond GeoJSON geometry level May 16, 2026
@prantogg prantogg marked this pull request as ready for review May 16, 2026 02:13
@prantogg prantogg requested a review from jiayuasu as a code owner May 16, 2026 02:13
@jiayuasu jiayuasu added this to the sedona-1.9.1 milestone May 17, 2026
@jiayuasu jiayuasu merged commit cf93840 into apache:master May 17, 2026
42 of 43 checks passed
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.

2 participants