From 3f35eacae77609272d2903a4a27a28bcb5ccbdfc Mon Sep 17 00:00:00 2001 From: Neeharika-Sompalli Date: Fri, 12 Jan 2024 13:35:59 -0600 Subject: [PATCH] fix NPE adding null values to readCache --- .../com/hedera/node/app/spi/state/ReadableKVStateBase.java | 6 ++++-- .../com/hedera/node/app/spi/state/WritableKVStateBase.java | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/hedera-node/hedera-app-spi/src/main/java/com/hedera/node/app/spi/state/ReadableKVStateBase.java b/hedera-node/hedera-app-spi/src/main/java/com/hedera/node/app/spi/state/ReadableKVStateBase.java index f036e74d90f5..04d508ff47b7 100644 --- a/hedera-node/hedera-app-spi/src/main/java/com/hedera/node/app/spi/state/ReadableKVStateBase.java +++ b/hedera-node/hedera-app-spi/src/main/java/com/hedera/node/app/spi/state/ReadableKVStateBase.java @@ -68,7 +68,9 @@ public V get(@NonNull K key) { Objects.requireNonNull(key); if (!hasBeenRead(key)) { final var value = readFromDataSource(key); - markRead(key, value); + if (value != null) { + markRead(key, value); + } } return readCache.get(key); } @@ -121,7 +123,7 @@ public void reset() { * @param key The key * @param value The value */ - protected final void markRead(@NonNull K key, @Nullable V value) { + protected final void markRead(@NonNull K key, @NonNull V value) { readCache.put(key, value); } diff --git a/hedera-node/hedera-app-spi/src/main/java/com/hedera/node/app/spi/state/WritableKVStateBase.java b/hedera-node/hedera-app-spi/src/main/java/com/hedera/node/app/spi/state/WritableKVStateBase.java index 4dd73b5d0fe3..cdd899e14d48 100644 --- a/hedera-node/hedera-app-spi/src/main/java/com/hedera/node/app/spi/state/WritableKVStateBase.java +++ b/hedera-node/hedera-app-spi/src/main/java/com/hedera/node/app/spi/state/WritableKVStateBase.java @@ -110,7 +110,9 @@ public final V getForModify(@NonNull final K key) { // We have not queried this key before, so let's look it up and store that we have // read this key. And then return the value. final var val = getForModifyFromDataSource(key); - markRead(key, val); + if(val != null){ + markRead(key, val); + } return val; }