Skip to content

Commit 0a80020

Browse files
committed
Merge pull request docker-java#474 from KostyaSha/backportNullFix
Fix periodic pull failure (2.x)
2 parents e96754c + bdcd89d commit 0a80020

File tree

2 files changed

+72
-2
lines changed

2 files changed

+72
-2
lines changed

src/main/java/com/github/dockerjava/core/async/JsonStreamProcessor.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.fasterxml.jackson.core.JsonParser;
1111
import com.fasterxml.jackson.core.JsonToken;
1212
import com.fasterxml.jackson.databind.ObjectMapper;
13+
import com.fasterxml.jackson.databind.node.ObjectNode;
1314
import com.github.dockerjava.api.async.ResultCallback;
1415

1516
/**
@@ -41,8 +42,12 @@ public void processResponseStream(InputStream response, ResultCallback<T> result
4142
JsonToken nextToken = jp.nextToken();
4243
while (!closed && nextToken != null && nextToken != JsonToken.END_OBJECT) {
4344
try {
44-
T next = OBJECT_MAPPER.readValue(jp, clazz);
45-
resultCallback.onNext(next);
45+
ObjectNode objectNode = OBJECT_MAPPER.readTree(jp);
46+
// exclude empty item serialization into class #461
47+
if (!(objectNode.size() == 0)) {
48+
T next = OBJECT_MAPPER.treeToValue(objectNode, clazz);
49+
resultCallback.onNext(next);
50+
}
4651
} catch (Exception e) {
4752
resultCallback.onError(e);
4853
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Created on 16.02.2016
3+
*/
4+
package com.github.dockerjava.core.async;
5+
6+
import static org.testng.Assert.assertFalse;
7+
8+
import java.io.ByteArrayInputStream;
9+
import java.io.Closeable;
10+
import java.io.IOException;
11+
import java.io.InputStream;
12+
import java.util.ArrayList;
13+
import java.util.List;
14+
15+
import org.testng.annotations.Test;
16+
17+
import com.github.dockerjava.api.async.ResultCallback;
18+
import com.github.dockerjava.api.model.PullResponseItem;
19+
20+
21+
/**
22+
*
23+
* @author Marcus Linke
24+
*
25+
*/
26+
public class JsonStreamProcessorTest {
27+
28+
@Test
29+
public void processEmptyJson() throws Exception {
30+
31+
InputStream response = new ByteArrayInputStream("{}".getBytes());
32+
33+
JsonStreamProcessor<PullResponseItem> jsonStreamProcessor = new JsonStreamProcessor<PullResponseItem>(PullResponseItem.class);
34+
35+
final List<Boolean> completed = new ArrayList<Boolean>();
36+
37+
jsonStreamProcessor.processResponseStream(response, new ResultCallback<PullResponseItem>() {
38+
39+
@Override
40+
public void close() throws IOException {
41+
}
42+
43+
@Override
44+
public void onStart(Closeable closeable) {
45+
}
46+
47+
@Override
48+
public void onNext(PullResponseItem object) {
49+
assertFalse(true, "onNext called for empty json");
50+
}
51+
52+
@Override
53+
public void onError(Throwable throwable) {
54+
}
55+
56+
@Override
57+
public void onComplete() {
58+
completed.add(true);
59+
}
60+
});
61+
62+
assertFalse(completed.isEmpty(), "Stream processing not completed");
63+
}
64+
65+
}

0 commit comments

Comments
 (0)