Skip to content

Commit 54d7697

Browse files
committed
Fix CME for invalid links on multiple locales field
1 parent 015218c commit 54d7697

File tree

6 files changed

+179
-2
lines changed

6 files changed

+179
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

55
## Version [5.0.1][unreleased] - (in development)
6-
- TBA.
6+
- Fixed: ConcurrentModificationException when localized link field points to invalid entry.
77

88
## Version [5.0.0] - (2015-10-27)
99
- Changed: `CDAArray.items()` now contains ONLY top level resources (no linked resources). All resources are available via `CDAArray.assets()` and `CDAArray.entries()` by ID.

src/main/java/com/contentful/java/cda/ResourceUtils.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,22 @@ static void resolveSingleLink(CDAEntry entry, CDAField field, ArrayResource arra
119119
if (value == null) {
120120
return;
121121
}
122+
Set<String> toRemove = new HashSet<String>();
122123
for (String locale : value.keySet()) {
123124
String linkId = getLinkId(value.get(locale));
124125
if (linkId == null) {
125126
continue;
126127
}
127128
CDAResource resource = findLinkedResource(array, linkType, linkId);
128129
if (resource == null) {
129-
value.remove(locale);
130+
toRemove.add(locale);
130131
} else {
131132
value.put(locale, resource);
132133
}
133134
}
135+
for (String locale : toRemove) {
136+
value.remove(locale);
137+
}
134138
}
135139

136140
static String getLinkId(Object link) {

src/test/java/com/contentful/java/cda/SyncTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,17 @@ public void testRawFields() throws Exception {
129129
assertThat(rawArray).isNotNull();
130130
assertThat(rawArray.get("en-US").get(0)).containsKey("sys");
131131
}
132+
133+
@Test
134+
@Enqueue(
135+
defaults = { },
136+
value = {
137+
"links_invalid/space.json",
138+
"links_invalid/content_types.json",
139+
"links_invalid/sync_initial.json"
140+
}
141+
)
142+
public void invalidLinkDoesNotThrow() throws Exception {
143+
client.sync().fetch();
144+
}
132145
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"sys": {
3+
"type": "Array"
4+
},
5+
"total": 2,
6+
"skip": 0,
7+
"limit": 100,
8+
"items": [
9+
{
10+
"name": "child",
11+
"fields": [
12+
{
13+
"name": "name",
14+
"id": "name",
15+
"type": "Symbol",
16+
"localized": false
17+
}
18+
],
19+
"description": "",
20+
"displayField": "name",
21+
"sys": {
22+
"space": {
23+
"sys": {
24+
"type": "Link",
25+
"linkType": "Space",
26+
"id": "dc9j5zkjikxm"
27+
}
28+
},
29+
"type": "ContentType",
30+
"id": "71tYS0GavSkUMsokUWmAW4",
31+
"revision": 1,
32+
"createdAt": "2015-10-22T20:53:20.595Z",
33+
"updatedAt": "2015-10-22T20:53:20.595Z"
34+
}
35+
},
36+
{
37+
"name": "parent",
38+
"fields": [
39+
{
40+
"name": "child",
41+
"id": "child",
42+
"type": "Link",
43+
"linkType": "Entry",
44+
"localized": true
45+
}
46+
],
47+
"description": "",
48+
"sys": {
49+
"space": {
50+
"sys": {
51+
"type": "Link",
52+
"linkType": "Space",
53+
"id": "dc9j5zkjikxm"
54+
}
55+
},
56+
"type": "ContentType",
57+
"id": "59TAIUBW5OaOSS4WgE8M4s",
58+
"revision": 1,
59+
"createdAt": "2015-10-28T17:47:44.061Z",
60+
"updatedAt": "2015-10-28T17:47:44.061Z"
61+
}
62+
}
63+
]
64+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"sys": {
3+
"type": "Space",
4+
"id": "dc9j5zkjikxm"
5+
},
6+
"name": "sp",
7+
"locales": [
8+
{
9+
"code": "en-US",
10+
"default": true,
11+
"name": "U.S. English"
12+
},
13+
{
14+
"code": "es",
15+
"default": false,
16+
"name": "Spanish"
17+
}
18+
]
19+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"sys": {
3+
"type": "Array"
4+
},
5+
"items": [
6+
{
7+
"sys": {
8+
"space": {
9+
"sys": {
10+
"type": "Link",
11+
"linkType": "Space",
12+
"id": "dc9j5zkjikxm"
13+
}
14+
},
15+
"type": "Entry",
16+
"contentType": {
17+
"sys": {
18+
"type": "Link",
19+
"linkType": "ContentType",
20+
"id": "59TAIUBW5OaOSS4WgE8M4s"
21+
}
22+
},
23+
"id": "2PovwSgHUce0AsokOswsqA",
24+
"revision": 1,
25+
"createdAt": "2015-10-28T17:48:13.629Z",
26+
"updatedAt": "2015-10-28T17:48:13.629Z"
27+
},
28+
"fields": {
29+
"child": {
30+
"en-US": {
31+
"sys": {
32+
"type": "Link",
33+
"linkType": "Entry",
34+
"id": "INVALID"
35+
}
36+
},
37+
"es": {
38+
"sys": {
39+
"type": "Link",
40+
"linkType": "Entry",
41+
"id": "51oWCPywfKyAs62gk66GUk"
42+
}
43+
}
44+
}
45+
}
46+
},
47+
{
48+
"sys": {
49+
"space": {
50+
"sys": {
51+
"type": "Link",
52+
"linkType": "Space",
53+
"id": "dc9j5zkjikxm"
54+
}
55+
},
56+
"type": "Entry",
57+
"contentType": {
58+
"sys": {
59+
"type": "Link",
60+
"linkType": "ContentType",
61+
"id": "71tYS0GavSkUMsokUWmAW4"
62+
}
63+
},
64+
"id": "51oWCPywfKyAs62gk66GUk",
65+
"revision": 1,
66+
"createdAt": "2015-10-28T17:47:56.133Z",
67+
"updatedAt": "2015-10-28T17:47:56.133Z"
68+
},
69+
"fields": {
70+
"name": {
71+
"en-US": "foo"
72+
}
73+
}
74+
}
75+
],
76+
"nextSyncUrl": "https://cdn.contentful.com/spaces/dc9j5zkjikxm/sync?sync_token=w5ZGw6JFwqZmVcKsE8Kow4grw45QdyYXJj7CgcO3PzMvSsO7MHrCgQNTwo0mNcKzwqRmMMKWfcKdwrzCug9iLSZwwptrw4fDjUrDicKJwqkywr_DlRYwchTDscOSw4spXTLCpX5twpvCmMKewqEZwo7Cm8Oz"
77+
}

0 commit comments

Comments
 (0)