[BUG] Generated serializers throw NullPointerException on null list elements (e.g. GetTasksResponse task.status.slices)
Maintainer thường phản hồi trong vòng 1 ngày
@bhuvanvkunte-ux đang làm issue này rồi.
Từ ngày 30/11/2026.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- Nửa ngày
- Mức phù hợp với người mới
- 72/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- java
- Lĩnh vực
- backend-api-design
Hướng nghiên cứu
Start with Type/directSerializer.mustache in java-codegen, then inspect the generated Status.serializeInternal method and its list serialization tests. Check how the template handles null elements for maps versus objects, and run the relevant code generation and serializer tests. Done means generated serializers write JSON null for null list elements without throwing, while preserving serialization of non-null elements.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What is the bug?
A typed response that the client has deserialized can't always be serialized back to JSON. When OpenSearch returns an array containing null elements, the deserializer keeps them as null list elements (ArrayDeserializer, JsonpDeserializerBase.java#L341), but the generated serializers iterate the list and call serialize(...) on every element without a null check, throwing a NullPointerException.
We hit it when getting a running sliced update-by-query (slices > 1), i.e. GET _tasks/<task_id>, with openSearchClient.tasks().get(new GetTasksRequest.Builder().taskId(taskId).build()). While slices are still running, OpenSearch reports them as null in task.status.slices, so serializing the returned GetTasksResponse (e.g. to log or forward it as JSON) fails in Status.serializeInternal:
java.lang.NullPointerException: Cannot invoke "org.opensearch.client.opensearch._types.BulkByScrollTaskStatusOrException.serialize(jakarta.json.stream.JsonGenerator, org.opensearch.client.json.JsonpMapper)" because "item0" is null
at org.opensearch.client.opensearch.tasks.Status.serializeInternal(Status.java:401)
at org.opensearch.client.opensearch.tasks.Status.serialize(Status.java:343)
at org.opensearch.client.opensearch.tasks.TaskInfoBase.serializeInternal(TaskInfoBase.java:307)
at org.opensearch.client.opensearch.tasks.TaskInfoBase.serialize(TaskInfoBase.java:244)
at org.opensearch.client.opensearch.tasks.GetTasksResponse.serializeInternal(GetTasksResponse.java:144)
at org.opensearch.client.opensearch.tasks.GetTasksResponse.serialize(GetTasksResponse.java:125)
The same applies to GET _tasks?detailed=true while such a task is running, since OpenSearch only includes the task status when detailed is set.
This is intended server behavior, the same in OpenSearch 2.13.0, 2.19.8, 3.10.1 and on main: the leader task of a sliced request only knows the status of slices that have finished (LeaderBulkByScrollTaskState#getStatus), and BulkByScrollTask.Status writes the others as null (BulkByScrollTask.java#L647-L655).
How can one reproduce the bug?
No cluster is needed: deserialize a GET _tasks/<task_id> response whose status.slices contains a null, then serialize it back.
Dependencies: org.opensearch.client:opensearch-java:3.11.0, jakarta.json:jakarta.json-api:2.1.3, com.fasterxml.jackson.core:jackson-databind:2.18.2 (with jackson-core and jackson-annotations) and a JSON-P provider, e.g. org.eclipse.parsson:parsson:1.1.7. With the jars in lib/, run it with java -cp 'lib/*' Repro.java.
Repro.java
import java.io.StringReader;
import java.io.StringWriter;
import org.opensearch.client.json.jackson.JacksonJsonpMapper;
import org.opensearch.client.opensearch.tasks.GetTasksResponse;
public class Repro {
// GET _tasks/<task_id> of a running update-by-query with slices=2,
// where slice 0 hasn't finished yet (OpenSearch reports it as null)
static final String JSON = """
{
"completed": false,
"task": {
"node": "node-1",
"id": 1234,
"type": "transport",
"action": "indices:data/write/update/byquery",
"status": {
"total": 200, "updated": 100, "created": 0, "deleted": 0, "batches": 1,
"version_conflicts": 0, "noops": 0, "retries": { "bulk": 0, "search": 0 },
"throttled_millis": 0, "requests_per_second": -1.0, "throttled_until_millis": 0,
"slices": [
null,
{
"slice_id": 1, "total": 100, "updated": 100, "created": 0, "deleted": 0, "batches": 1,
"version_conflicts": 0, "noops": 0, "retries": { "bulk": 0, "search": 0 },
"throttled_millis": 0, "requests_per_second": -1.0, "throttled_until_millis": 0
}
]
},
"description": "update-by-query [my-index]",
"start_time_in_millis": 1700000000000,
"running_time_in_nanos": 1000,
"cancellable": true,
"cancelled": false,
"headers": {}
}
}
""";
public static void main(String[] args) {
var mapper = new JacksonJsonpMapper();
// Deserializing works: the null slice becomes a null list element
GetTasksResponse response;
try (var parser = mapper.jsonProvider().createParser(new StringReader(JSON))) {
response = GetTasksResponse._DESERIALIZER.deserialize(parser, mapper);
}
System.out.println("slices = " + response.task().status().slices());
// Serializing the same object back throws a NullPointerException
var writer = new StringWriter();
try (var generator = mapper.jsonProvider().createGenerator(writer)) {
response.serialize(generator, mapper);
}
System.out.println(writer);
}
}
Output:
slices = [null, org.opensearch.client.opensearch._types.BulkByScrollTaskStatusOrException@ff59bcbb]
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "org.opensearch.client.opensearch._types.BulkByScrollTaskStatusOrException.serialize(jakarta.json.stream.JsonGenerator, org.opensearch.client.json.JsonpMapper)" because "item0" is null
at org.opensearch.client.opensearch.tasks.Status.serializeInternal(Status.java:401)
...
What is the expected behavior?
Serializing a response the client has deserialized produces JSON equivalent to the original, writing null for null list elements (here "slices": [null, {...}]), rather than throwing.
What is your host/environment?
- opensearch-java 3.11.0 (also reproduced on 3.9.0); same code on
mainat 75dfaf9 - Java 25,
JacksonJsonpMapper - OpenSearch 2.13 (the repro above doesn't need a cluster)
Do you have any screenshots?
No.
Do you have any additional context?
- The deserializer started accepting
nullarray elements in #687 (fixing #176); the serialization side wasn't changed accordingly. - The loop comes from the code generator: in
Type/directSerializer.mustache, the list branch only null-checks elements when they are maps, so every generated list-of-objects serializer has the same issue, not justStatus.slices. Writinggenerator.writeNull()fornullelements there would fix it across the generated code. - Related, but different: #666 (deserialization failure when reading a failed task), and the
_listAddAllNPE for anulllist field fixed in #2041.
- Ngôn ngữ chính
- Java
- Star
- 164
- Fork
- 260
- Merge trung bình
- 18 giờ 51 phút
- Pull request đã merge (30 ngày)
- 57
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của opensearch-project/opensearch-java
-
bug untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
opensearch-project/opensearch-java#2342 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
opensearch-project/opensearch-java#2188 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] "shape" should not be required in GeoShapeQueryFieldCó thể làm lại được @lsh1215 đã nhận 152 ngày trước và không có pull request nào đang mở. Đang mởbug untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
opensearch-project/opensearch-java#2011 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
opensearch-project/opensearch-java#2008 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] ISM types lastUpdatedTime is susceptible to int overflowCó thể đã có người làm @gingeekrishna đã nhận 148 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
opensearch-project/opensearch-java#1898 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của opensearch-project/opensearch-java
Issue tương tự
-
Add contributing guideCó thể đã có người làm @WadekarPrashant đã nhận hôm nay. Đang mởgood first issue
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
jenkinsci/gitea-checks-plugin#382 · 1 bình luận ·
-
enhancement infra
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
Maintainer thường phản hồi trong vòng 1 ngày
-
5.0.x backport bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
spring-cloud/spring-cloud-function#1569 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Move the spring-cloud-commons version and BOM import from the bus parent to the stream parentCó thể đã có người làm @olegz đã nhận hôm nay. Đang mởtask
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
spring-cloud/spring-cloud-stream#3355 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Netcracker/qubership-integration-platform#1417 ·
Maintainer thường phản hồi trong vòng 1 ngày