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

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


The following commit(s) were added to refs/heads/trunk by this push:
     new d08dfdc6f92 KAFKA-20802 Avoid NPE in thread leak reporting (#22827)
d08dfdc6f92 is described below

commit d08dfdc6f92d28e3bcd40989c4c5066c88f17882
Author: Eric Chang <[email protected]>
AuthorDate: Thu Jul 16 06:52:26 2026 +0800

    KAFKA-20802 Avoid NPE in thread leak reporting (#22827)
    
    ## Summary
    
    - handle a missing thread group while building thread-leak reports
    - preserve the existing leak-detection behavior and label the group as
    `<terminated>`
    
    ## Motivation
    
    `ClusterTestExtensions#afterEach` formats detected threads with
    `Thread#getThreadGroup().getName()`. A thread can terminate after
    `DetectThreadLeak#newThreads()` captures it but before the message is
    formatted. Since `Thread#getThreadGroup()` returns `null` for a
    terminated thread, the reporting path throws an NPE instead of reporting
    the detected thread.
    
    CI failure:
    
    
https://github.com/apache/kafka/actions/runs/29228499012/job/86748625389#step:6:136310
    
    Jira: https://issues.apache.org/jira/browse/KAFKA-20802
    
    Related: https://issues.apache.org/jira/browse/KAFKA-17189
    
    ## Testing
    
    - `./gradlew :test-common:test-common-runtime:test --tests
    org.apache.kafka.common.test.junit.ClusterTestExtensionsUnitTest`
    - `./gradlew :test-common:test-common-runtime:spotlessCheck`
    
    Reviewers: Ken Huang <[email protected]>, Chia-Ping Tsai
    <[email protected]>
---
 .../apache/kafka/common/test/junit/ClusterTestExtensions.java    | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git 
a/test-common/test-common-runtime/src/main/java/org/apache/kafka/common/test/junit/ClusterTestExtensions.java
 
b/test-common/test-common-runtime/src/main/java/org/apache/kafka/common/test/junit/ClusterTestExtensions.java
index d6f1984a6e7..8bb1ae1509e 100644
--- 
a/test-common/test-common-runtime/src/main/java/org/apache/kafka/common/test/junit/ClusterTestExtensions.java
+++ 
b/test-common/test-common-runtime/src/main/java/org/apache/kafka/common/test/junit/ClusterTestExtensions.java
@@ -182,11 +182,12 @@ public class ClusterTestExtensions implements 
TestTemplateInvocationContextProvi
             if (detectThreadLeak == null) {
                 return;
             }
+
             List<Thread> threads = detectThreadLeak.newThreads();
-            assertTrue(threads.isEmpty(), "Thread leak detected: " +
-                threads.stream().map(t -> {
-                    return t.getThreadGroup().getName() + "/" + t.getName();
-                }).collect(Collectors.joining(", ")));
+            assertTrue(threads.isEmpty(), "Thread leak detected: " + 
threads.stream()
+                .map(t -> Optional.ofNullable(t.getThreadGroup())
+                    .map(ThreadGroup::getName).orElse("<terminated>") + "/" + 
t.getName())
+                .collect(Collectors.joining(", ")));
         }
     }
 

Reply via email to