Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Add document lifecycle guide and runnable sample ([#2017](https://github.com/opensearch-project/opensearch-java/pull/2017))

### Fixed
- Fix `NullPointerException` in `_listAddAll` when server returns JSON `null` for a list field ([#2041](https://github.com/opensearch-project/opensearch-java/pull/2041))

## [Unreleased 3.x]
### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public class ShardProfile implements PlainJsonSerializable, ToCopyableBuilder<Sh
@Nonnull
private final List<AggregationProfile> aggregations;

@Nullable
private final FetchProfile fetch;
@Nonnull
private final List<FetchProfile> fetch;

@Nonnull
private final String id;
Expand All @@ -77,7 +77,7 @@ public class ShardProfile implements PlainJsonSerializable, ToCopyableBuilder<Sh

private ShardProfile(Builder builder) {
this.aggregations = ApiTypeHelper.unmodifiableRequired(builder.aggregations, this, "aggregations");
this.fetch = builder.fetch;
this.fetch = ApiTypeHelper.unmodifiable(builder.fetch);
this.id = ApiTypeHelper.requireNonNull(builder.id, this, "id");
this.searches = ApiTypeHelper.unmodifiableRequired(builder.searches, this, "searches");
}
Expand All @@ -97,8 +97,8 @@ public final List<AggregationProfile> aggregations() {
/**
* API name: {@code fetch}
*/
@Nullable
public final FetchProfile fetch() {
@Nonnull
public final List<FetchProfile> fetch() {
return this.fetch;
}

Expand Down Expand Up @@ -136,9 +136,13 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
}
generator.writeEnd();

if (this.fetch != null) {
if (ApiTypeHelper.isDefined(this.fetch)) {
generator.writeKey("fetch");
this.fetch.serialize(generator, mapper);
generator.writeStartArray();
for (FetchProfile item0 : this.fetch) {
item0.serialize(generator, mapper);
}
generator.writeEnd();
}

generator.writeKey("id");
Expand Down Expand Up @@ -171,22 +175,22 @@ public static Builder builder() {
public static class Builder extends ObjectBuilderBase implements CopyableBuilder<Builder, ShardProfile> {
private List<AggregationProfile> aggregations;
@Nullable
private FetchProfile fetch;
private List<FetchProfile> fetch;
private String id;
private List<SearchProfile> searches;

public Builder() {}

private Builder(ShardProfile o) {
this.aggregations = _listCopy(o.aggregations);
this.fetch = o.fetch;
this.fetch = _listCopy(o.fetch);
this.id = o.id;
this.searches = _listCopy(o.searches);
}

private Builder(Builder o) {
this.aggregations = _listCopy(o.aggregations);
this.fetch = o.fetch;
this.fetch = _listCopy(o.fetch);
this.id = o.id;
this.searches = _listCopy(o.searches);
}
Expand Down Expand Up @@ -237,15 +241,36 @@ public final Builder aggregations(Function<AggregationProfile.Builder, ObjectBui

/**
* API name: {@code fetch}
*
* <p>
* Adds all elements of <code>list</code> to <code>fetch</code>.
* </p>
*/
@Nonnull
public final Builder fetch(List<FetchProfile> list) {
this.fetch = _listAddAll(this.fetch, list);
return this;
}

/**
* API name: {@code fetch}
*
* <p>
* Adds one or more values to <code>fetch</code>.
* </p>
*/
@Nonnull
public final Builder fetch(@Nullable FetchProfile value) {
this.fetch = value;
public final Builder fetch(FetchProfile value, FetchProfile... values) {
this.fetch = _listAdd(this.fetch, value, values);
return this;
}

/**
* API name: {@code fetch}
*
* <p>
* Adds a value to <code>fetch</code> using a builder lambda.
* </p>
*/
@Nonnull
public final Builder fetch(Function<FetchProfile.Builder, ObjectBuilder<FetchProfile>> fn) {
Expand Down Expand Up @@ -325,7 +350,7 @@ public ShardProfile build() {

protected static void setupShardProfileDeserializer(ObjectDeserializer<ShardProfile.Builder> op) {
op.add(Builder::aggregations, JsonpDeserializer.arrayDeserializer(AggregationProfile._DESERIALIZER), "aggregations");
op.add(Builder::fetch, FetchProfile._DESERIALIZER, "fetch");
op.add(Builder::fetch, JsonpDeserializer.arrayDeserializer(FetchProfile._DESERIALIZER), "fetch");
op.add(Builder::id, JsonpDeserializer.stringDeserializer(), "id");
op.add(Builder::searches, JsonpDeserializer.arrayDeserializer(SearchProfile._DESERIALIZER), "searches");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,15 @@ protected static <T> List<T> _listAdd(List<T> list, T value, T... values) {

/** Add all elements of a list to a (possibly {@code null}) list */
protected static <T> List<T> _listAddAll(List<T> list, List<T> values) {
if (values == null) {
// Server returned JSON null for a list field; treat as empty to avoid NPE.
// See https://github.com/opensearch-project/opensearch-java/issues/1813
return list;
}
if (list == null) {
// Keep the original list to avoid an unnecessary copy.
// It will be copied if we add more values.
return Objects.requireNonNull(values);
return values;
} else {
list = _mutableList(list);
list.addAll(values);
Expand Down
4 changes: 3 additions & 1 deletion java-codegen/opensearch-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52512,7 +52512,9 @@ components:
items:
$ref: '#/components/schemas/_core.search___SearchProfile'
fetch:
$ref: '#/components/schemas/_core.search___FetchProfile'
type: array
items:
$ref: '#/components/schemas/_core.search___FetchProfile'
required:
- aggregations
- id
Expand Down
Loading