From e85c88c56a702dc2868fb50724b21bb2d87d95fe 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 **Auto-cherry-pick to `3.3.x` & `3.2.x`** --- .../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 b7c7af65..315d18cb 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 @@ -368,14 +368,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; }