opensearch-project / opensearch-project/opensearch-java

[BUG] `required` spec not respected for maps and lists

Open
#1,813 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.