You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by ch...@apache.org on 2026/03/26 09:31:10 UTC

(kafka) branch 4.2 updated: MINOR: Fix potential NPE (#21846)

This is an automated email from the ASF dual-hosted git repository.

chia7712 pushed a commit to branch 4.2
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/4.2 by this push:
     new 28e01b7a3b8 MINOR: Fix potential NPE (#21846)
28e01b7a3b8 is described below

commit 28e01b7a3b871c39eabf8b2efe5d429c5e527efc
Author: Andrew Schofield <as...@confluent.io>
AuthorDate: Thu Mar 26 04:31:03 2026 -0500

    MINOR: Fix potential NPE (#21846)
    
    Fixes a potential NPE in `ShareFetch`. I have hit it once during
    testing, but only once. Fix in progress on trunk and will include in
    4.3.0. This is worth putting into 4.2.1.
    
    Reviewers: Nilesh Kumar <ni...@gmail.com>, aliehsaeedii
     <as...@confluent.io>, Chia-Ping Tsai <ch...@gmail.com>
---
 .../java/org/apache/kafka/clients/consumer/internals/ShareFetch.java | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clients/src/main/java/org/apache/kafka/clients/consumer/internals/ShareFetch.java b/clients/src/main/java/org/apache/kafka/clients/consumer/internals/ShareFetch.java
index 83a43cb69ae..093791aa711 100644
--- a/clients/src/main/java/org/apache/kafka/clients/consumer/internals/ShareFetch.java
+++ b/clients/src/main/java/org/apache/kafka/clients/consumer/internals/ShareFetch.java
@@ -250,7 +250,10 @@ public class ShareFetch<K, V> {
     public int renew(Map<TopicIdPartition, Acknowledgements> acknowledgementsMap, Optional<Integer> acquisitionLockTimeoutMs) {
         int recordsRenewed = 0;
         for (Map.Entry<TopicIdPartition, Acknowledgements> entry : acknowledgementsMap.entrySet()) {
-            recordsRenewed += batches.get(entry.getKey()).renew(entry.getValue());
+            ShareInFlightBatch<K, V> batch = batches.get(entry.getKey());
+            if (batch != null) {
+                recordsRenewed += batch.renew(entry.getValue());
+            }
         }
         acquisitionLockTimeoutMsRenewed = acquisitionLockTimeoutMs;
         return recordsRenewed;