Skip to content

Commit

Permalink
fix NPE adding null values to readCache
Browse files Browse the repository at this point in the history
  • Loading branch information
Neeharika-Sompalli committed Jan 12, 2024
1 parent e3bdd08 commit 3f35eac
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 3f35eac

Please sign in to comment.