From d86363af4e2b66b78c333d6c64184caea17bb15c Mon Sep 17 00:00:00 2001 From: Kim JaeYeon <48614095+ghgh415263@users.noreply.github.com> Date: Thu, 20 Mar 2025 01:01:10 +0900 Subject: [PATCH] GH-3810: Move the logging statement after the conditional statement in KafkaTestUtils (#3811) Fixes: 3810 Issue link: https://github.com/spring-projects/spring-kafka/issues/3810 Signed-off-by: kjy1994 (cherry picked from commit e85c88c56a702dc2868fb50724b21bb2d87d95fe) --- .../springframework/kafka/test/utils/KafkaTestUtils.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spring-kafka-test/src/main/java/org/springframework/kafka/test/utils/KafkaTestUtils.java b/spring-kafka-test/src/main/java/org/springframework/kafka/test/utils/KafkaTestUtils.java index c4902dce..12fd1d15 100644 --- a/spring-kafka-test/src/main/java/org/springframework/kafka/test/utils/KafkaTestUtils.java +++ b/spring-kafka-test/src/main/java/org/springframework/kafka/test/utils/KafkaTestUtils.java @@ -364,14 +364,14 @@ public final class KafkaTestUtils { do { long t1 = System.currentTimeMillis(); ConsumerRecords received = consumer.poll(Duration.ofMillis(remaining)); + if (received == null) { + throw new IllegalStateException("null received from consumer.poll()"); + } logger.debug(() -> "Received: " + received.count() + ", " + received.partitions().stream() .flatMap(p -> received.records(p).stream()) // map to same format as send metadata toString() .map(r -> r.topic() + "-" + r.partition() + "@" + r.offset()).toList()); - if (received == null) { - throw new IllegalStateException("null received from consumer.poll()"); - } if (minRecords < 0) { return received; }