Skip to content

Commit cec4e52

Browse files
committed
Fix null pointer in merkle node when ipfs returns an error
1 parent 226e073 commit cec4e52

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/main/java/io/ipfs/api/MerkleNode.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@ public static MerkleNode fromJSON(Object rawjson) {
5757
if (rawjson instanceof String)
5858
return new MerkleNode((String)rawjson);
5959
Map json = (Map)rawjson;
60+
if ("error".equals(json.get("Type")))
61+
throw new IllegalStateException("Remote IPFS error: " + json.get("Message"));
6062
String hash = (String)json.get("Hash");
6163
if (hash == null)
6264
hash = (String)json.get("Key");
63-
if (hash == null)
64-
hash = (String)(((Map)json.get("Cid")).get("/"));
65+
if (hash == null && json.containsKey("Cid"))
66+
hash = (String) (((Map) json.get("Cid")).get("/"));
6567
Optional<String> name = json.containsKey("Name") ?
6668
Optional.of((String) json.get("Name")) :
6769
Optional.empty();
@@ -72,8 +74,6 @@ public static MerkleNode fromJSON(Object rawjson) {
7274
Optional<String> largeSize = rawSize instanceof String ?
7375
Optional.of((String) json.get("Size")) :
7476
Optional.empty();
75-
if ("error".equals(json.get("Type")))
76-
throw new IllegalStateException("Remote IPFS error: " + json.get("Message"));
7777
Optional<Integer> type = json.containsKey("Type") ?
7878
Optional.of((Integer) json.get("Type")) :
7979
Optional.empty();

0 commit comments

Comments
 (0)