prevent NPE in toString

pull/4/head
Zlatin Balevsky 2019-06-07 06:31:29 +01:00
parent 4a9e6d3b6b
commit 3f9ee887d6
1 changed files with 8 additions and 6 deletions

View File

@ -77,13 +77,15 @@ public class InfoHash {
public String toString() {
String rv = "InfoHash[root:"+Base32.encode(root) + " hashList:";
List<String> 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<String> 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;
}