From 6194941bb09db95cdd6512b5098f02331b872ef5 Mon Sep 17 00:00:00 2001
From: Kim Kern <kim.kern@fu-berlin.de>
Date: Wed, 13 Jul 2016 23:45:31 +0200
Subject: [PATCH] make AggregationContext nonnull

---
 .../actions/aggregation/ActionAggregationCancel.java      | 8 ++++++--
 src/main/java/fucoin/wallet/WalletImpl.java               | 3 ++-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/main/java/fucoin/actions/aggregation/ActionAggregationCancel.java b/src/main/java/fucoin/actions/aggregation/ActionAggregationCancel.java
index 49e4478..f0b831b 100644
--- a/src/main/java/fucoin/actions/aggregation/ActionAggregationCancel.java
+++ b/src/main/java/fucoin/actions/aggregation/ActionAggregationCancel.java
@@ -32,10 +32,14 @@ public class ActionAggregationCancel extends ActionAggregation {
 		if (isDone()) {
 			wallet.addExcludedNeighbor(sender);
 		}
-		if (!wallet.areAllNeighborsExcluded()) {
+		AggregationContext aggregationContext = wallet.getAggregationContext();
+		if (!wallet.areAllNeighborsExcluded() && !aggregationContext
+				.isDone()) {
 			continueAggregation(wallet);
+		} else if (aggregationContext.isDone() && !wallet.areAllNeighborsExcluded()) {
+			sendEndMessage(wallet);
 		} else if (wallet.hasAggregationContext()) {
-			sendAggregatedResult(wallet, wallet.getAggregationContext());
+			sendAggregatedResult(wallet, aggregationContext);
 			sendEndMessage(wallet);
 		}
 	}
diff --git a/src/main/java/fucoin/wallet/WalletImpl.java b/src/main/java/fucoin/wallet/WalletImpl.java
index 613f395..9afc7d3 100644
--- a/src/main/java/fucoin/wallet/WalletImpl.java
+++ b/src/main/java/fucoin/wallet/WalletImpl.java
@@ -11,6 +11,7 @@ import akka.actor.ActorRef;
 import akka.actor.Props;
 import fucoin.actions.ClientAction;
 import fucoin.actions.aggregation.AggregationContext;
+import fucoin.actions.aggregation.AggregationContext.AggregationContextBuilder;
 import fucoin.actions.join.ActionJoin;
 import fucoin.actions.join.ActionJoinAnswer;
 import fucoin.actions.join.ActionTellSupervisor;
@@ -29,7 +30,7 @@ public class WalletImpl extends AbstractWallet {
     private transient WalletGuiControl gui;
     private String preKnownNeighbourName;
     private boolean isActive;
-	private AggregationContext aggregationContext;
+	private AggregationContext aggregationContext = new AggregationContextBuilder(null, null, amount).build();
 	private boolean hasPendingAggregationRequest = false;
     private ConcurrentLinkedQueue<ActorRef> deferedSupervisorReceivers = new ConcurrentLinkedQueue<>();
 	private transient final EvictingQueue<UUID> handledAggregationRequests = EvictingQueue.create(10);
-- 
GitLab