Skip to content

Commit 40ca5de

Browse files
committed
fix(batch): avoid NPE in TaskHandle.POISON#toString
https://open.spotify.com/track/5XcZRgJv3zMhTqCyESjQrF?si=53697170efd34e2a
1 parent 4aef132 commit 40ca5de

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

src/main/java/io/weaviate/client6/v1/api/collections/batch/TaskHandle.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ private TaskHandle() {
8383
}
8484

8585
/**
86-
* Creates a new task containing the same data as this task and {@link retries}
87-
* counter incremented by 1. The {@link acked} and {@link result} futures
86+
* Creates a new task containing the same data as this task and {@link #retries}
87+
* counter incremented by 1. The {@link #acked} and {@link #result} futures
8888
* are not copied to the returned task.
8989
*
9090
* @return Task handle.
@@ -163,14 +163,17 @@ public CompletableFuture<Result> result() {
163163
* Number of times this task has been retried. Since {@link TaskHandle} is
164164
* immutable, this value does not change, but retrying a task via
165165
* {@link BatchContext#retry} is reflected in the returned handle's
166-
* {@link #timesRetried}.
166+
* timesRetried.
167167
*/
168168
public int timesRetried() {
169169
return retries;
170170
}
171171

172172
@Override
173173
public String toString() {
174+
if (this == POISON) {
175+
return "TaskHandle<POISON>";
176+
}
174177
return "TaskHandle<id=%s, retried=%d, created=%s>".formatted(id(), retries, createdAt);
175178
}
176179
}

src/test/java/io/weaviate/client6/v1/api/collections/batch/TaskHandleTest.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class TaskHandleTest {
3333
CollectionHandleDefaults.of(CollectionHandleDefaults.none()));
3434

3535
@Test
36-
public void testTaskHandle_WeaviateObject_success() {
36+
public void test_newTaskHandle_WeaviateObject_success() {
3737
TaskHandle taskHandle = new TaskHandle(OBJECT, OBJECT_PROTO);
3838

3939
Assertions.assertThat(taskHandle)
@@ -58,7 +58,7 @@ public void testTaskHandle_WeaviateObject_success() {
5858
}
5959

6060
@Test
61-
public void testTaskHandle_WeaviateObject_error() {
61+
public void test_newTaskHandle_WeaviateObject_error() {
6262
TaskHandle taskHandle = new TaskHandle(OBJECT, OBJECT_PROTO);
6363

6464
Assertions.assertThat(taskHandle)
@@ -83,7 +83,7 @@ public void testTaskHandle_WeaviateObject_error() {
8383
}
8484

8585
@Test
86-
public void testTaskHandle_BatchReference_success() {
86+
public void test_newTaskHandle_BatchReference_success() {
8787
TaskHandle taskHandle = new TaskHandle(REFERENCE, REFERENCE_PROTO);
8888

8989
Assertions.assertThat(taskHandle)
@@ -108,7 +108,7 @@ public void testTaskHandle_BatchReference_success() {
108108
}
109109

110110
@Test
111-
public void testTaskHandle_BatchReference_error() {
111+
public void test_newTaskHandle_BatchReference_error() {
112112
TaskHandle taskHandle = new TaskHandle(REFERENCE, REFERENCE_PROTO);
113113

114114
Assertions.assertThat(taskHandle)
@@ -133,7 +133,7 @@ public void testTaskHandle_BatchReference_error() {
133133
}
134134

135135
@Test
136-
public void testTaskHandle_retry() {
136+
public void test_retry() {
137137
TaskHandle taskHandle = new TaskHandle(OBJECT, OBJECT_PROTO);
138138
Assertions.assertThat(taskHandle).returns(0, TaskHandle::timesRetried);
139139

@@ -147,6 +147,12 @@ public void testTaskHandle_retry() {
147147
.extracting(TaskHandle::data).isEqualTo(taskHandle.data());
148148
}
149149

150+
@Test
151+
public void test_toString_POISON() {
152+
Assertions.assertThat(TaskHandle.POISON.toString())
153+
.isEqualTo("TaskHandle<POISON>");
154+
}
155+
150156
private void assertAcked(TaskHandle taskHandle, boolean expect) {
151157
Assertions.assertThat(taskHandle)
152158
.extracting(TaskHandle::isAcked)

0 commit comments

Comments
 (0)