Skip to content

Conversation

@little-huang
Copy link
Contributor

Title

Guard against NPE when metadata is null during distance injection

Description

Adds a null check before injecting the distance property into metadata to prevent a NullPointerException if metadata is missing from the row record. The change is intentionally minimal and does not alter existing behavior beyond avoiding the crash.

Motivation / Background

Some search results do not carry metadata (or the metadata value is null). Calling JsonObject.addProperty(...) on a null reference throws an NPE and breaks the mapping pipeline.

Changes

Add a null guard around the distance injection step to ensure we do not call addProperty(...) on a null metadata.

Behavior

No functional changes other than preventing the NPE when metadata is null.

Related issues

Fixes #4115

@sobychacko
Copy link
Contributor

@little-huang
Copy link
Contributor Author

Please address the DCO commit signing. https://spring.io/blog/2025/01/06/hello-dco-goodbye-cla-simplifying-contributions-to-spring

Thanks, @sobychacko — signed off and force-pushed. DCO is green now.

@sobychacko sobychacko added this to the 1.1.0.M1 milestone Aug 14, 2025
@sobychacko sobychacko added the bug Something isn't working label Aug 14, 2025
@sobychacko sobychacko merged commit 1e28e30 into spring-projects:main Aug 14, 2025
2 checks passed
spring-builds pushed a commit that referenced this pull request Aug 14, 2025
Adds a null check before injecting the distance property into metadata to prevent a NullPointerException
if metadata is missing from the row record.

The change is intentionally minimal and does not alter existing behavior beyond avoiding the crash.

Some search results do not carry metadata (or the metadata value is null).
Calling JsonObject.addProperty(...) on a null reference throws an NPE and breaks the mapping pipeline.

Add a null guard around the distance injection step to ensure we do not call addProperty(...) on a null metadata.

Fixes #4115

Signed-off-by: little_huang <[email protected]>
(cherry picked from commit 1e28e30)
scionaltera pushed a commit to scionaltera/spring-ai that referenced this pull request Sep 3, 2025
)

Adds a null check before injecting the distance property into metadata to prevent a NullPointerException
if metadata is missing from the row record. 

The change is intentionally minimal and does not alter existing behavior beyond avoiding the crash.

Some search results do not carry metadata (or the metadata value is null). 
Calling JsonObject.addProperty(...) on a null reference throws an NPE and breaks the mapping pipeline.

Add a null guard around the distance injection step to ensure we do not call addProperty(...) on a null metadata.

Fixes spring-projects#4115
Auto-cherry-pick to 1.0.x

Signed-off-by: little_huang <[email protected]>
chedim pushed a commit to couchbaselabs/spring-ai that referenced this pull request Sep 19, 2025
)

Adds a null check before injecting the distance property into metadata to prevent a NullPointerException
if metadata is missing from the row record. 

The change is intentionally minimal and does not alter existing behavior beyond avoiding the crash.

Some search results do not carry metadata (or the metadata value is null). 
Calling JsonObject.addProperty(...) on a null reference throws an NPE and breaks the mapping pipeline.

Add a null guard around the distance injection step to ensure we do not call addProperty(...) on a null metadata.

Fixes spring-projects#4115
Auto-cherry-pick to 1.0.x

Signed-off-by: little_huang <[email protected]>
Willam2004 pushed a commit to Willam2004/spring-ai that referenced this pull request Oct 11, 2025
)

Adds a null check before injecting the distance property into metadata to prevent a NullPointerException
if metadata is missing from the row record.

The change is intentionally minimal and does not alter existing behavior beyond avoiding the crash.

Some search results do not carry metadata (or the metadata value is null).
Calling JsonObject.addProperty(...) on a null reference throws an NPE and breaks the mapping pipeline.

Add a null guard around the distance injection step to ensure we do not call addProperty(...) on a null metadata.

Fixes spring-projects#4115
Auto-cherry-pick to 1.0.x

Signed-off-by: little_huang <[email protected]>
Signed-off-by: 家娃 <[email protected]>
ralla0405 pushed a commit to ralla0405/spring-ai that referenced this pull request Nov 28, 2025
)

Adds a null check before injecting the distance property into metadata to prevent a NullPointerException
if metadata is missing from the row record.

The change is intentionally minimal and does not alter existing behavior beyond avoiding the crash.

Some search results do not carry metadata (or the metadata value is null).
Calling JsonObject.addProperty(...) on a null reference throws an NPE and breaks the mapping pipeline.

Add a null guard around the distance injection step to ensure we do not call addProperty(...) on a null metadata.

Fixes spring-projects#4115
Auto-cherry-pick to 1.0.x

Signed-off-by: little_huang <[email protected]>
Signed-off-by: logan-mac <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NullPointerException when metadata is null during distance injection in Document mapping

2 participants