From ade173bdc762d0fe8ac97a5e189f6802156231a7 Mon Sep 17 00:00:00 2001 From: Munawar Date: Mon, 9 Oct 2023 15:45:57 -0700 Subject: [PATCH] fix: Add protection against a possible null dereference issue (#1258) * Comment: Added protection against a possible null dereference issue. * run linter --------- Co-authored-by: Sydney Munro --- .../storage/contrib/nio/SeekableByteChannelPrefetcher.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/SeekableByteChannelPrefetcher.java b/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/SeekableByteChannelPrefetcher.java index dbdd4e5a..41632f8c 100644 --- a/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/SeekableByteChannelPrefetcher.java +++ b/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/SeekableByteChannelPrefetcher.java @@ -357,8 +357,10 @@ public ByteBuffer fetch(long position) throws InterruptedException, ExecutionExc nbMiss++; ensureFetching(blockIndex); candidate = fetching; - buf = candidate.getBuf(); - full.add(candidate); + if (candidate != null) { + buf = candidate.getBuf(); + full.add(candidate); + } fetching = null; ensureFetching(blockIndex + 1); return buf;