Skip to content

Commit 43650a4

Browse files
authored
GH-2826: Fix KafkaAdmin NPE With Bad Config Name
Resolves #2832 **cherry-pick to 3.0.x, 2.9.x**
1 parent c98e4cd commit 43650a4

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

spring-kafka/src/main/java/org/springframework/kafka/core/KafkaAdmin.java

+4
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,10 @@ private Map<ConfigResource, List<ConfigEntry>> checkTopicsForConfigMismatches(
415415
if (topicOptional.isPresent() && topicOptional.get().configs() != null) {
416416
for (Map.Entry<String, String> desiredConfigParameter : topicOptional.get().configs().entrySet()) {
417417
ConfigEntry actualConfigParameter = topicConfig.getValue().get(desiredConfigParameter.getKey());
418+
if (actualConfigParameter == null) {
419+
throw new IllegalStateException("Topic property '" + desiredConfigParameter.getKey()
420+
+ "' does not exist");
421+
}
418422
if (!desiredConfigParameter.getValue().equals(actualConfigParameter.value())) {
419423
configMismatchesEntries.add(actualConfigParameter);
420424
}

spring-kafka/src/test/java/org/springframework/kafka/core/KafkaAdminTests.java

+10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.kafka.core;
1818

1919
import static org.assertj.core.api.Assertions.assertThat;
20+
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
2021
import static org.awaitility.Awaitility.await;
2122

2223
import java.lang.reflect.Method;
@@ -176,6 +177,15 @@ public void testAddTopicsAndAddPartitions() throws Exception {
176177
&& configResourceConfigMap.get(new ConfigResource(Type.TOPIC, "noConfigAddLater"))
177178
.get("retention.ms").value().equals("1000");
178179
});
180+
181+
assertThatIllegalStateException().isThrownBy(() -> this.admin.createOrModifyTopics(mismatchconfig,
182+
TopicBuilder.name("noConfigAddLater")
183+
.partitions(2)
184+
.replicas(1)
185+
.config("no.such.config.key", "1000")
186+
.build()))
187+
.withMessageContaining("no.such.config.key");
188+
179189
}
180190

181191
@Test

0 commit comments

Comments
 (0)