Skip to content

Commit

Permalink
spring-projectsGH-2826: Fix KafkaAdmin NPE With Bad Config Name
Browse files Browse the repository at this point in the history
Resolves spring-projects#2832

**cherry-pick to 3.0.x, 2.9.x**
  • Loading branch information
garyrussell committed Oct 9, 2023
1 parent c98e4cd commit cdc957e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,10 @@ private Map<ConfigResource, List<ConfigEntry>> checkTopicsForConfigMismatches(
if (topicOptional.isPresent() && topicOptional.get().configs() != null) {
for (Map.Entry<String, String> desiredConfigParameter : topicOptional.get().configs().entrySet()) {
ConfigEntry actualConfigParameter = topicConfig.getValue().get(desiredConfigParameter.getKey());
if (actualConfigParameter == null) {
throw new IllegalStateException("Topic property '" + desiredConfigParameter.getKey()
+ "' does not exist");
}
if (!desiredConfigParameter.getValue().equals(actualConfigParameter.value())) {
configMismatchesEntries.add(actualConfigParameter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.springframework.kafka.core;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.awaitility.Awaitility.await;

import java.lang.reflect.Method;
Expand Down Expand Up @@ -176,6 +177,15 @@ public void testAddTopicsAndAddPartitions() throws Exception {
&& configResourceConfigMap.get(new ConfigResource(Type.TOPIC, "noConfigAddLater"))
.get("retention.ms").value().equals("1000");
});

assertThatIllegalStateException().isThrownBy(() -> this.admin.createOrModifyTopics(mismatchconfig,
TopicBuilder.name("noConfigAddLater")
.partitions(2)
.replicas(1)
.config("no.such.config.key", "1000")
.build()))
.withMessageContaining("no.such.config.key");

}

@Test
Expand Down

0 comments on commit cdc957e

Please sign in to comment.