Skip to content

Commit 041cacd

Browse files
committed
Merge branch '2.9' into 2.10
2 parents d994b2d + 83264a7 commit 041cacd

File tree

4 files changed

+41
-9
lines changed

4 files changed

+41
-9
lines changed

release-notes/CREDITS-2.x

+5
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,11 @@ René Kschamer (flawi@github)
842842
as value type
843843
(2.9.8)
844844

845+
Joffrey Bion (joffrey-bion@github)
846+
* Reported #2265: Inconsistent handling of Collections$UnmodifiableList vs
847+
Collections$UnmodifiableRandomAccessList
848+
(2.9.9)
849+
845850
Christoph Breitkopf (bokesan@github)
846851
* Reported #2217: Suboptimal memory allocation in `TextNode.getBinaryValue()`
847852
(2.10.0)

release-notes/VERSION-2.x

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ Project: jackson-databind
4646
enableDefaultTyping causing NPE
4747
(reported by MeyerNils@github)
4848
#2251: Getter that returns an abstract collection breaks a delegating `@JsonCreator`
49+
#2265: Inconsistent handling of Collections$UnmodifiableList vs Collections$UnmodifiableRandomAccessList
50+
(reported by Joffrey B)
4951
- Prevent String coercion of `null` in `WritableObjectId` when calling `JsonGenerator.writeObjectId()`,
5052
mostly relevant for formats like YAML that have native Object Ids
5153

src/main/java/com/fasterxml/jackson/databind/deser/impl/JavaUtilCollectionsDeserializers.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ public abstract class JavaUtilCollectionsDeserializers
4040

4141
private final static Class<?> CLASS_UNMODIFIABLE_SET;
4242
private final static Class<?> CLASS_UNMODIFIABLE_LIST;
43+
44+
/* 02-Mar-2019, tatu: for [databind#2265], need to consider possible alternate type...
45+
* which we essentially coerce into the other one
46+
*/
47+
private final static Class<?> CLASS_UNMODIFIABLE_LIST_ALIAS;
4348
private final static Class<?> CLASS_UNMODIFIABLE_MAP;
4449

4550
static {
@@ -50,7 +55,9 @@ public abstract class JavaUtilCollectionsDeserializers
5055
List<?> list = Collections.singletonList(Boolean.TRUE);
5156
CLASS_SINGLETON_LIST = list.getClass();
5257
CLASS_UNMODIFIABLE_LIST = Collections.unmodifiableList(list).getClass();
53-
58+
// for [databind#2265]
59+
CLASS_UNMODIFIABLE_LIST_ALIAS = Collections.unmodifiableList(new LinkedList<Object>()).getClass();
60+
5461
Map<?,?> map = Collections.singletonMap("a", "b");
5562
CLASS_SINGLETON_MAP = map.getClass();
5663
CLASS_UNMODIFIABLE_MAP = Collections.unmodifiableMap(map).getClass();
@@ -69,7 +76,8 @@ public static JsonDeserializer<?> findForCollection(DeserializationContext ctxt,
6976
conv = converter(TYPE_SINGLETON_LIST, type, List.class);
7077
} else if (type.hasRawClass(CLASS_SINGLETON_SET)) {
7178
conv = converter(TYPE_SINGLETON_SET, type, Set.class);
72-
} else if (type.hasRawClass(CLASS_UNMODIFIABLE_LIST)) {
79+
// [databind#2265]: we may have another impl type for unmodifiable Lists, check both
80+
} else if (type.hasRawClass(CLASS_UNMODIFIABLE_LIST) || type.hasRawClass(CLASS_UNMODIFIABLE_LIST_ALIAS)) {
7381
conv = converter(TYPE_UNMODIFIABLE_LIST, type, List.class);
7482
} else if (type.hasRawClass(CLASS_UNMODIFIABLE_SET)) {
7583
conv = converter(TYPE_UNMODIFIABLE_SET, type, Set.class);
+24-7
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import com.fasterxml.jackson.databind.BaseMapTest;
77
import com.fasterxml.jackson.databind.ObjectMapper;
88

9-
// Unit tests for [databind#1868], related
10-
public class TestDefaultForUtilCollections1868 extends BaseMapTest
9+
// Unit tests for [databind#1868], [databind#1880], [databind#2265]
10+
public class UtilCollectionsTypesTest extends BaseMapTest
1111
{
1212
private final ObjectMapper DEFAULT_MAPPER = new ObjectMapper();
1313
{
@@ -60,6 +60,21 @@ public void testUnmodifiableList() throws Exception {
6060
_verifyCollection(Collections.unmodifiableList(Arrays.asList("first", "second")));
6161
}
6262

63+
// [databind#2265]
64+
public void testUnmodifiableListFromLinkedList() throws Exception {
65+
final List<String> input = new LinkedList<>();
66+
input.add("first");
67+
input.add("second");
68+
69+
// Can't use simple "_verifyCollection" as type may change; instead use
70+
// bit more flexible check:
71+
Collection<?> act = _writeReadCollection(Collections.unmodifiableList(input));
72+
assertEquals(input, act);
73+
74+
// and this check may be bit fragile (may need to revisit), but is good enough for now:
75+
assertEquals(Collections.unmodifiableList(new ArrayList<>(input)).getClass(), act.getClass());
76+
}
77+
6378
public void testUnmodifiableSet() throws Exception
6479
{
6580
Set<String> input = new LinkedHashSet<>(Arrays.asList("first", "second"));
@@ -96,15 +111,17 @@ public void testArraysAsList() throws Exception
96111
/**********************************************************
97112
*/
98113

99-
protected void _verifyCollection(Collection<?> exp) throws Exception
100-
{
101-
String json = DEFAULT_MAPPER.writeValueAsString(exp);
102-
Collection<?> act = DEFAULT_MAPPER.readValue(json, Collection.class);
103-
114+
protected void _verifyCollection(Collection<?> exp) throws Exception {
115+
Collection<?> act = _writeReadCollection(exp);
104116
assertEquals(exp, act);
105117
assertEquals(exp.getClass(), act.getClass());
106118
}
107119

120+
protected Collection<?> _writeReadCollection(Collection<?> input) throws Exception {
121+
final String json = DEFAULT_MAPPER.writeValueAsString(input);
122+
return DEFAULT_MAPPER.readValue(json, Collection.class);
123+
}
124+
108125
protected void _verifyMap(Map<?,?> exp) throws Exception
109126
{
110127
String json = DEFAULT_MAPPER.writeValueAsString(exp);

0 commit comments

Comments
 (0)