Skip to content

Commit 0f91036

Browse files
committed
Backport fix #2564 to 2.10(.2)
1 parent 15bec49 commit 0f91036

File tree

5 files changed

+44
-44
lines changed

5 files changed

+44
-44
lines changed

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Project: jackson-databind
1414
(reported by Fabian L)
1515
#2560: Check `WRAP_EXCEPTIONS` in `CollectionDeserializer.handleNonArray()`
1616
(reported by Stefan W)
17+
#2564: Fix `IllegalArgumentException` on empty input collection for `ArrayBlockingQueue`
18+
(repoted, fix suggested by yamert89@github)
1719
#2567: Incorrect target type for arrays when providing nulls and nulls are disabled
1820
(reported by João G)
1921

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,13 @@ public Collection<Object> deserialize(JsonParser p, DeserializationContext ctxt,
9494
}
9595
// Ok: must point to START_ARRAY (or equivalent)
9696
if (!p.isExpectedStartArrayToken()) {
97-
return handleNonArray(p, ctxt, new ArrayBlockingQueue<Object>(1));
97+
return handleNonArray(p, ctxt, new ArrayBlockingQueue<>(1));
9898
}
99-
result0 = super.deserialize(p, ctxt, new ArrayList<Object>());
100-
if (result0.isEmpty()) return new ArrayBlockingQueue<Object>(1, false);
101-
return new ArrayBlockingQueue<Object>(result0.size(), false, result0);
99+
result0 = super.deserialize(p, ctxt, new ArrayList<>());
100+
if (result0.isEmpty()) {
101+
return new ArrayBlockingQueue<>(1, false);
102+
}
103+
return new ArrayBlockingQueue<>(result0.size(), false, result0);
102104
}
103105

104106
@Override

src/test/java/com/fasterxml/jackson/databind/deser/TestEmptyArrayBlockingQueueDeser.java

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/test/java/com/fasterxml/jackson/databind/deser/jdk/MapRelatedTypesDeserTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
public class MapRelatedTypesDeserTest
99
extends BaseMapTest
1010
{
11-
private final ObjectMapper MAPPER = new ObjectMapper();
11+
private final ObjectMapper MAPPER = newJsonMapper();
1212

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

0 commit comments

Comments
 (0)