From aa05c89732bb57d7dabbc0b8571f9a2deea0951e Mon Sep 17 00:00:00 2001 From: Sotatek-DucPhung Date: Tue, 4 Jun 2024 10:40:13 +0700 Subject: [PATCH] fix: null pointer ex when poolFetchList from koios is empty --- .../rewards/schedule/service/PoolInfoDataService.java | 5 +++++ .../rewards/service/impl/PoolHistoryFetchingServiceImpl.java | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/schedule/service/PoolInfoDataService.java b/src/main/java/org/cardanofoundation/explorer/rewards/schedule/service/PoolInfoDataService.java index 58c98e38..2d67d766 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/schedule/service/PoolInfoDataService.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/schedule/service/PoolInfoDataService.java @@ -16,6 +16,7 @@ import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; import io.micrometer.common.util.StringUtils; import rest.koios.client.backend.api.base.exception.ApiException; @@ -49,6 +50,10 @@ public CompletableFuture fetchData(List poolIds) { int currentEpoch = epochService.getCurrentEpoch(); var dataFromKoios = getPoolInfoList(poolIds); + if(CollectionUtils.isEmpty(dataFromKoios)) { + return CompletableFuture.completedFuture(Boolean.TRUE); + } + var poolHashMap = poolHashRepository.findByViewIn(poolIds).stream() .collect(Collectors.toMap(PoolHash::getView, Function.identity())); diff --git a/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/PoolHistoryFetchingServiceImpl.java b/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/PoolHistoryFetchingServiceImpl.java index 1eb29cdd..977f9657 100644 --- a/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/PoolHistoryFetchingServiceImpl.java +++ b/src/main/java/org/cardanofoundation/explorer/rewards/service/impl/PoolHistoryFetchingServiceImpl.java @@ -17,6 +17,7 @@ import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; import io.micrometer.common.util.StringUtils; import rest.koios.client.backend.api.base.exception.ApiException; @@ -60,6 +61,10 @@ public CompletableFuture fetchData(String poolId) { var dataFromKoios = getPoolHistoryList(poolId); var poolHistoryCheckpoint = poolHistoryCheckpointRepository.findByView(poolId); + if(CollectionUtils.isEmpty(dataFromKoios)) { + return CompletableFuture.completedFuture(Boolean.TRUE); + } + Map poolHistoryList = dataFromKoios.stream() .filter(poolHistory -> poolHistory.getEpochNo() < currentEpoch)