From df9b2aec9056e4dfadb8c7c0df5028cbe4bfcf3a Mon Sep 17 00:00:00 2001 From: huzhenyuan Date: Fri, 24 Aug 2018 11:05:06 +0800 Subject: [PATCH 1/2] fix bug for getUnchecked --- src/main/java/org/tron/core/db/BlockIndexStore.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/tron/core/db/BlockIndexStore.java b/src/main/java/org/tron/core/db/BlockIndexStore.java index 123fccd3336..cbb0519e745 100644 --- a/src/main/java/org/tron/core/db/BlockIndexStore.java +++ b/src/main/java/org/tron/core/db/BlockIndexStore.java @@ -30,7 +30,7 @@ public void put(BlockId id) { public BlockId get(Long num) throws ItemNotFoundException { BytesCapsule value = getUnchecked(ByteArray.fromLong(num)); - if(value == null) { + if(value.getData() == null) { throw new ItemNotFoundException("number: " + num + " is not found!"); } return new BlockId(Sha256Hash.wrap(value.getData()), num); From 54409b20649817df6e49cc523f3f66820b43ee8a Mon Sep 17 00:00:00 2001 From: Matt Yue Date: Fri, 24 Aug 2018 11:13:21 +0800 Subject: [PATCH 2/2] value == null || value.getData() == null --- src/main/java/org/tron/core/db/BlockIndexStore.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/tron/core/db/BlockIndexStore.java b/src/main/java/org/tron/core/db/BlockIndexStore.java index cbb0519e745..2cfd3d7ae28 100644 --- a/src/main/java/org/tron/core/db/BlockIndexStore.java +++ b/src/main/java/org/tron/core/db/BlockIndexStore.java @@ -1,8 +1,8 @@ package org.tron.core.db; +import java.util.Arrays; import org.apache.commons.lang3.ArrayUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.tron.common.utils.ByteArray; @@ -11,8 +11,6 @@ import org.tron.core.capsule.BytesCapsule; import org.tron.core.exception.ItemNotFoundException; -import java.util.Arrays; - @Component public class BlockIndexStore extends TronStoreWithRevoking { @@ -30,7 +28,7 @@ public void put(BlockId id) { public BlockId get(Long num) throws ItemNotFoundException { BytesCapsule value = getUnchecked(ByteArray.fromLong(num)); - if(value.getData() == null) { + if (value == null || value.getData() == null) { throw new ItemNotFoundException("number: " + num + " is not found!"); } return new BlockId(Sha256Hash.wrap(value.getData()), num);