Skip to content

Commit 15bec49

Browse files
yamert89cowtowncoder
authored andcommitted
Fix IllegalArgumentException on empty input collection for ArrayBlockingQueue concrete class
1 parent f760b6d commit 15bec49

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/main/java/com/fasterxml/jackson/databind/deser/std/ArrayBlockingQueueDeserializer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public Collection<Object> deserialize(JsonParser p, DeserializationContext ctxt,
9797
return handleNonArray(p, ctxt, new ArrayBlockingQueue<Object>(1));
9898
}
9999
result0 = super.deserialize(p, ctxt, new ArrayList<Object>());
100+
if (result0.isEmpty()) return new ArrayBlockingQueue<Object>(1, false);
100101
return new ArrayBlockingQueue<Object>(result0.size(), false, result0);
101102
}
102103

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.fasterxml.jackson.databind.deser;
2+
3+
import com.fasterxml.jackson.core.JsonProcessingException;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import org.junit.Assert;
6+
import org.junit.Test;
7+
8+
import java.io.IOException;
9+
import java.util.Collection;
10+
import java.util.concurrent.ArrayBlockingQueue;
11+
12+
public class TestEmptyArrayBlockingQueueDeser {
13+
14+
@Test
15+
public void emptyCollectionDeser() throws JsonProcessingException, IOException {
16+
ObjectMapper om = new ObjectMapper();
17+
String json = om.writeValueAsString(new RemoteEntity());
18+
Entity entity = om.readValue(json, Entity.class);
19+
Assert.assertEquals(0, entity.values.size());
20+
}
21+
22+
23+
24+
private static class RemoteEntity{
25+
private Collection<Double> values = new ArrayBlockingQueue<>(20);
26+
27+
public Collection<Double> getValues() {
28+
return values;
29+
}
30+
}
31+
32+
private static class Entity{
33+
private ArrayBlockingQueue<Double> values;
34+
35+
public Collection<Double> getValues() {
36+
return values;
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)