Fix NPE in _listAddAll when server returns JSON null for a list field - #2041
Open
gingeekrishna wants to merge 5 commits into
Open
Fix NPE in _listAddAll when server returns JSON null for a list field#2041gingeekrishna wants to merge 5 commits into
gingeekrishna wants to merge 5 commits into
Conversation
gingeekrishna
requested review from
Bukhtawar,
VachaShah,
Xtansia,
madhusudhankonda,
reta,
saratvemulapalli and
szczepanczykd
as code owners
July 5, 2026 08:50
gingeekrishna
added a commit
to gingeekrishna/opensearch-java
that referenced
this pull request
Jul 5, 2026
Signed-off-by: Radhakrishnan Pachyappan <gingeekrishna@gmail.com>
Hailong-am
reviewed
Jul 29, 2026
| $ref: '#/components/schemas/_core.search___FetchProfile' | ||
| type: array | ||
| items: | ||
| $ref: '#/components/schemas/_core.search___FetchProfile' |
Contributor
There was a problem hiding this comment.
should we update https://github.com/opensearch-project/opensearch-api-specification/blob/5691b4a54b7cf485a7c5d1e1b53c1987348f4e13/spec/schemas/_core.search.yaml#L201-L202 here and sync from it?
Collaborator
There was a problem hiding this comment.
Correct, this is the way we generate Java client, thank you @Hailong-am
gingeekrishna
added a commit
to gingeekrishna/opensearch-java
that referenced
this pull request
Aug 16, 2026
Signed-off-by: Radhakrishnan Pachyappan <gingeekrishna@gmail.com>
gingeekrishna
force-pushed
the
fix/1813-listaddall-null-values
branch
from
August 16, 2026 16:15
dc9939a to
2abeeb0
Compare
gingeekrishna
added a commit
to gingeekrishna/opensearch-java
that referenced
this pull request
Aug 30, 2026
Signed-off-by: Radhakrishnan Pachyappan <gingeekrishna@gmail.com>
gingeekrishna
force-pushed
the
fix/1813-listaddall-null-values
branch
from
August 30, 2026 06:28
2abeeb0 to
8cad090
Compare
…etchProfile> OpenSearch returns fetch as a JSON array in profile responses but the spec defined it as a single FetchProfile object. This caused: UnexpectedJsonEventException: Unexpected JSON event 'START_ARRAY' instead of '[START_OBJECT, KEY_NAME]' Change the spec to type: array / items: FetchProfile and update the generated ShardProfile.java to use List<FetchProfile> with array serialization and arrayDeserializer, matching the pattern already used by aggregations and searches in the same class. Fixes opensearch-project#1965 Signed-off-by: Radhakrishnan Pachyappan <gingeekrishna@gmail.com>
Signed-off-by: Radhakrishnan Pachyappan <gingeekrishna@gmail.com>
_listAddAll(list, values) threw NullPointerException via Objects.requireNonNull(values) when the incoming values list was null. This happens when OpenSearch returns JSON null for an optional list field (e.g. ism_template in ISM Policy), causing deserialization to fail with an NPE inside the builder. Guard against null values by returning the existing list unchanged when values is null, consistent with the intent of treating a missing or null list as equivalent to an empty one. Fixes opensearch-project#1813 Signed-off-by: Radhakrishnan Pachyappan <gingeekrishnan@gmail.com>
Signed-off-by: Radhakrishnan Pachyappan <gingeekrishna@gmail.com>
gingeekrishna
force-pushed
the
fix/1813-listaddall-null-values
branch
from
September 4, 2026 05:57
8cad090 to
af9cdc0
Compare
The previous commit made _listAddAll tolerate a null values list by returning the existing list unchanged. That was too broad: _listAddAll is the same helper generated builder setters use for direct public API calls (e.g. b.storedFields(nullFields)), and ClassStructureTest. testListSetters explicitly asserts that passing null to a list setter throws NullPointerException - a real, tested API contract this broke. CI caught it: testListSetters[json-b] and testListSetters[jackson] both failed after the previous push. The actual bug (opensearch-project#1813) is specific to deserialization: when the server sends JSON null for an array field, JsonpDeserializer's default deserialize(parser, mapper) short-circuits to Java null for any deserializer that doesn't accept Event.VALUE_NULL - which is exactly what ArrayDeserializer.acceptedEvents() didn't do. That Java null then gets passed straight into the generated field setter (the same setter public callers use), which passes it to _listAddAll, which throws. Fix it at the deserializer instead: ArrayDeserializer now accepts Event.VALUE_NULL and returns an empty list for it, so a null array in server JSON becomes an empty list before it ever reaches the setter - no different from an absent field. This is the correct, narrowly- scoped fix: it only changes what array deserialization does with a JSON null, leaving _listAddAll (and the public builder API contract tested by testListSetters) exactly as it always was. Reverts the _listAddAll change from the previous commit. Adds JsonpDeserializerBaseTest#testNullArray covering the top-level-null case, alongside the existing testNullArrayItem which covers null items within an array. Signed-off-by: Radhakrishnan P <gingeekrishna@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1813
_listAddAll(list, values)threwNullPointerExceptionviaObjects.requireNonNull(values)whenvalueswasnull. This happens when OpenSearch returns JSONnullfor an optional list field (e.g.ism_templatein ISM Policy), causing deserialization to fail:Fix: Guard against null
valuesby returning the existing list unchanged whenvaluesis null. Same logic applied to_mapPutAllwould follow the same pattern if similar issues arise for maps.