From 3f9ee887d6accadc1a746843fcae370122dc9e73 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Fri, 7 Jun 2019 06:31:29 +0100 Subject: [PATCH] prevent NPE in toString --- core/src/main/java/com/muwire/core/InfoHash.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/com/muwire/core/InfoHash.java b/core/src/main/java/com/muwire/core/InfoHash.java index ae4cc690..df01372f 100644 --- a/core/src/main/java/com/muwire/core/InfoHash.java +++ b/core/src/main/java/com/muwire/core/InfoHash.java @@ -77,13 +77,15 @@ public class InfoHash { public String toString() { String rv = "InfoHash[root:"+Base32.encode(root) + " hashList:"; - List b32HashList = new ArrayList<>(hashList.length / SIZE); - byte [] tmp = new byte[SIZE]; - for (int i = 0; i < hashList.length / SIZE; i++) { - System.arraycopy(hashList, SIZE * i, tmp, 0, SIZE); - b32HashList.add(Base32.encode(tmp)); + List b64HashList = new ArrayList<>(); + if (hashList != null) { + byte [] tmp = new byte[SIZE]; + for (int i = 0; i < hashList.length / SIZE; i++) { + System.arraycopy(hashList, SIZE * i, tmp, 0, SIZE); + b64HashList.add(Base32.encode(tmp)); + } } - rv += b32HashList.toString(); + rv += b64HashList.toString(); rv += "]"; return rv; }