Skip to content

Commit a5a762b

Browse files
committed
Merge pull request #97 from contentful/iss96
Fix NPE for null links
2 parents 5a5d123 + b5fbc56 commit a5a762b

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ static void resolveSingleLink(CDAEntry entry, CDAField field, ArrayResource arra
145145
}
146146

147147
static String getLinkId(Object link) {
148+
if (link == null) {
149+
return null;
150+
}
148151
if (link instanceof CDAResource) {
149152
// already resolved
150153
return ((CDAResource) link).id();

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,13 @@ public class LinkTest extends BaseTest {
5050

5151
assertThat((List<String>) container.getField("symbols")).containsExactly("a", "b", "c");
5252
}
53+
54+
@Test @Enqueue(defaults = {
55+
"links/space.json",
56+
"links/content_types.json"
57+
}, value = {
58+
"links/sync_empty_links.json"
59+
}) public void testEmptyLinks() throws Exception {
60+
client.sync().fetch();
61+
}
5362
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"sys": {
3+
"type": "Array"
4+
},
5+
"items": [
6+
{
7+
"sys": {
8+
"space": {
9+
"sys": {
10+
"type": "Link",
11+
"linkType": "Space",
12+
"id": "75oea9kejr52"
13+
}
14+
},
15+
"type": "Entry",
16+
"contentType": {
17+
"sys": {
18+
"type": "Link",
19+
"linkType": "ContentType",
20+
"id": "2s9novBkP2G0oasUaG8kCs"
21+
}
22+
},
23+
"id": "3vyEoAvlkk8yE4a8gCCkiu",
24+
"revision": 1,
25+
"createdAt": "2015-07-10T11:56:10.469Z",
26+
"updatedAt": "2015-07-10T11:56:10.469Z"
27+
},
28+
"fields": {
29+
"entry": {
30+
"en-US": null
31+
},
32+
"asset": {
33+
"en-US": null
34+
},
35+
"entries": {
36+
"en-US": []
37+
},
38+
"assets": {
39+
"en-US": []
40+
},
41+
"symbols": {
42+
"en-US": []
43+
}
44+
}
45+
}
46+
]
47+
}

0 commit comments

Comments
 (0)