From aa05c89732bb57d7dabbc0b8571f9a2deea0951e Mon Sep 17 00:00:00 2001 From: Sotatek-DucPhung Date: Tue, 4 Jun 2024 10:40:13 +0700 Subject: [PATCH 1/2] 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) From 671d0b6a1816423d661d5913e177bde6887f5fa6 Mon Sep 17 00:00:00 2001 From: Sotatek-DucPhung Date: Tue, 2 Jul 2024 09:50:35 +0700 Subject: [PATCH 2/2] chore: apply code formatter --- .../explorer/rewards/schedule/service/PoolInfoDataService.java | 2 +- .../rewards/service/impl/PoolHistoryFetchingServiceImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 2d67d766..c7bf04f2 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 @@ -50,7 +50,7 @@ public CompletableFuture fetchData(List poolIds) { int currentEpoch = epochService.getCurrentEpoch(); var dataFromKoios = getPoolInfoList(poolIds); - if(CollectionUtils.isEmpty(dataFromKoios)) { + if (CollectionUtils.isEmpty(dataFromKoios)) { return CompletableFuture.completedFuture(Boolean.TRUE); } 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 977f9657..c1be8a85 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 @@ -61,7 +61,7 @@ public CompletableFuture fetchData(String poolId) { var dataFromKoios = getPoolHistoryList(poolId); var poolHistoryCheckpoint = poolHistoryCheckpointRepository.findByView(poolId); - if(CollectionUtils.isEmpty(dataFromKoios)) { + if (CollectionUtils.isEmpty(dataFromKoios)) { return CompletableFuture.completedFuture(Boolean.TRUE); }