From dbd446788edb62da7cf272c24b053fc3ecd9fbe7 Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Thu, 14 Feb 2019 15:35:23 +1000 Subject: [PATCH] Fix NullPointerException - complete future with fast sync state not null. (#859) --- .../ethereum/eth/sync/fastsync/FastSyncActions.java | 4 ++-- .../ethereum/eth/sync/fastsync/FastSyncActionsTest.java | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncActions.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncActions.java index a52e1cfb1b..a6c37951f7 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncActions.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncActions.java @@ -82,7 +82,7 @@ public CompletableFuture waitForSuitablePeers(final FastSyncState if (ethContext.getEthPeers().availablePeerCount() > 0) { LOG.warn( "Fast sync timed out before minimum peer count was reached. Continuing with reduced peers."); - result.complete(null); + result.complete(fastSyncState); } else { LOG.warn( "Maximum wait time for fast sync reached but no peers available. Continuing to wait for any available peer."); @@ -98,7 +98,7 @@ public CompletableFuture waitForSuitablePeers(final FastSyncState LOG.error("Failed to find peers for fast sync", error); result.completeExceptionally(error); } else { - result.complete(null); + result.complete(fastSyncState); } return null; }); diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncActionsTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncActionsTest.java index 635cca91c5..9c32065ab2 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncActionsTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncActionsTest.java @@ -93,14 +93,15 @@ public void waitForPeersShouldSucceedIfEnoughPeersAreFound() { } final CompletableFuture result = fastSyncActions.waitForSuitablePeers(EMPTY_SYNC_STATE); - assertThat(result).isCompleted(); + assertThat(result).isCompletedWithValue(EMPTY_SYNC_STATE); } @Test public void waitForPeersShouldReportSuccessWhenTimeLimitReachedAndAPeerIsAvailable() { EthProtocolManagerTestUtil.createPeer(ethProtocolManager); timeoutCount.set(Integer.MAX_VALUE); - assertThat(fastSyncActions.waitForSuitablePeers(EMPTY_SYNC_STATE)).isCompleted(); + assertThat(fastSyncActions.waitForSuitablePeers(EMPTY_SYNC_STATE)) + .isCompletedWithValue(EMPTY_SYNC_STATE); } @Test @@ -111,7 +112,7 @@ public void waitForPeersShouldContinueWaitingUntilAtLeastOnePeerIsAvailable() { assertThat(result).isNotCompleted(); EthProtocolManagerTestUtil.createPeer(ethProtocolManager); - assertThat(result).isCompleted(); + assertThat(result).isCompletedWithValue(EMPTY_SYNC_STATE); } @Test