From 3ae733b416fe9e4b788f12113f1cf9f9cd9252a5 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Thu, 24 Jun 2021 11:17:47 +0200 Subject: [PATCH] avoid npe when no parts have been processed --- .../sparrowwallet/hummingbird/fountain/FountainDecoder.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sparrowwallet/hummingbird/fountain/FountainDecoder.java b/src/main/java/com/sparrowwallet/hummingbird/fountain/FountainDecoder.java index 59b11e7..9f01662 100644 --- a/src/main/java/com/sparrowwallet/hummingbird/fountain/FountainDecoder.java +++ b/src/main/java/com/sparrowwallet/hummingbird/fountain/FountainDecoder.java @@ -30,7 +30,7 @@ public class FountainDecoder { private final List queuedParts = new ArrayList<>(); public int getExpectedPartCount() { - return expectedPartIndexes.size(); + return expectedPartIndexes == null ? 0 : expectedPartIndexes.size(); } public Set getRecievedPartIndexes() { @@ -46,6 +46,10 @@ public class FountainDecoder { } public double getEstimatedPercentComplete() { + if(processedPartsCount == 0) { + return 0d; + } + double estimatedInputParts = (double)getExpectedPartCount() * 1.75; return Math.min(0.99, (double)processedPartsCount / estimatedInputParts); }