From d60154d893218d4da9560beab0f2be6fbc902647 Mon Sep 17 00:00:00 2001 From: Igor Artamonov Date: Tue, 16 Feb 2021 17:15:00 -0500 Subject: [PATCH] problem: nullpointer stacktrace if json is just "null" --- .../dshackle/upstream/ethereum/CacheRequested.kt | 3 ++- .../upstream/ethereum/CacheRequestedSpec.groovy | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/CacheRequested.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/CacheRequested.kt index e824f808..da386049 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/CacheRequested.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/CacheRequested.kt @@ -46,7 +46,8 @@ class CacheRequested( if (params.size != 1) { return } - val parsed = Global.objectMapper.readValue(json, TransactionReceiptJson::class.java) + // note: json could be a `null` value + val parsed = Global.objectMapper.readValue(json, TransactionReceiptJson::class.java) ?: return val value = DefaultContainer( TxId.from(parsed.transactionHash), BlockId.from(parsed.blockHash), diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/CacheRequestedSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/CacheRequestedSpec.groovy index 9a97b5d5..2b93c5dc 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/CacheRequestedSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/CacheRequestedSpec.groovy @@ -42,4 +42,17 @@ class CacheRequestedSpec extends Specification { }) } + def "Ignore null"() { + setup: + def caches = Mock(Caches) + CacheRequested instance = new CacheRequested(caches) + def json = 'null'.bytes + + when: + instance.cacheTxReceipt(["0x5929b36be4586c57bd87dfb7ea6be3b985c1f527fa3d69d221604b424aeb4197"], json) + + then: + 0 * caches.cacheReceipt(_, _) + } + }