opensearch-project / opensearch-project/opensearch-java
[BUG] `required` spec not respected for maps and lists
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 165
- Forks
- 250
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 26
Description
What is the bug?
In the spec, a null value can be allowed for lists, e.g. here:
https://github.com/opensearch-project/opensearch-api-specification/blob/963f90293d480015deaf352d1987bec2f18916c2/spec/schemas/ism._common.yaml#L50-L57
Deserializing these will fail with a NPE due to the Objects.requireNonNull in _listAddAll
How can one reproduce the bug?
ISM Policies can be created without nested ISM Templates. As an example, see the create policy request/response in the docs
However, reading a policy created like this without the client fails due to the list being null
java.lang.NullPointerException
at java.base/java.util.Objects.requireNonNull(Objects.java:233)
at org.opensearch.client.util.ObjectBuilderBase._listAddAll(ObjectBuilderBase.java:101)
at org.opensearch.client.opensearch.ism.Policy$Builder.ismTemplate(Policy.java:379)
at org.opensearch.client.json.ObjectDeserializer$FieldObjectDeserializer.deserialize(ObjectDeserializer.java:82)
at org.opensearch.client.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:185)
at org.opensearch.client.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:146)
at org.opensearch.client.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:87)
at org.opensearch.client.json.ObjectBuilderDeserializer.deserialize(ObjectBuilderDeserializer.java:91)
What is the expected behavior?
lists and maps should respect required like all other properties. If this is not possible, deserialization should take care of initializing them if they are missing from the JSON (however, the two representations would not be equal then)
What is your host/environment?
OS java client 3.2/3.3
Do you have any additional context?
I wonder why they are conditionally excluded from the required check. What is the reason for that?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing ObjectBuilderBase._listAddAll and Policy$Builder.ismTemplate through ObjectDeserializer, then inspect how the Java client generator handles required maps and lists from the API specification. Reproduce the ISM policy deserialization failure and verify that nullable or missing collections follow the specification without triggering a NullPointerException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 54/100