problem: nullpointer stacktrace if json is just "null"

This commit is contained in:
Igor Artamonov
2021-02-16 17:15:00 -05:00
parent 73d94879cd
commit d60154d893
2 changed files with 15 additions and 1 deletions

View File

@@ -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<TransactionReceiptJson>(
TxId.from(parsed.transactionHash),
BlockId.from(parsed.blockHash),

View File

@@ -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(_, _)
}
}