chia7712 commented on code in PR #22827:
URL: https://github.com/apache/kafka/pull/22827#discussion_r3580574318
##########
test-common/test-common-runtime/src/main/java/org/apache/kafka/common/test/junit/ClusterTestExtensions.java:
##########
@@ -182,11 +182,16 @@ public void afterEach(ExtensionContext context) {
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(", ")));
+
+ List<String> threadNames =
detectThreadLeak.newThreads().stream().flatMap(thread -> {
Review Comment:
It is a bit intricate to me. Could we use `Optional` to handle it?
```java
assertTrue(threads.isEmpty(), "Thread leak detected: " +
threads.stream()
.map(t -> Optional.ofNullable(t.getThreadGroup())
.map(ThreadGroup::getName).orElse("<terminated>") + "/"
+ t.getName()).collect(Collectors.joining(", ")));
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]