Skip to content

Commit 5fa31c3

Browse files
garyrussellartembilan
authored andcommitted
GH-926: Fix error handler detection
Fixes #926 - Use correct wired error handler for key/value - Fix sonar issue about the properties being nullable
1 parent f4a0a23 commit 5fa31c3

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2018 the original author or authors.
2+
* Copyright 2016-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -103,6 +103,7 @@ default Map<String, Object> getConfigurationProperties() {
103103
* @return the deserializer.
104104
* @since 2.0
105105
*/
106+
@Nullable
106107
default Deserializer<K> getKeyDeserializer() {
107108
throw new UnsupportedOperationException("'getKeyDeserializer()' is not supported");
108109
}
@@ -113,6 +114,7 @@ default Deserializer<K> getKeyDeserializer() {
113114
* @return the deserializer.
114115
* @since 2.0
115116
*/
117+
@Nullable
116118
default Deserializer<V> getValueDeserializer() {
117119
throw new UnsupportedOperationException("'getKeyDeserializer()' is not supported");
118120
}

spring-kafka/src/main/java/org/springframework/kafka/listener/KafkaMessageListenerContainer.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -546,16 +546,18 @@ else if (listener instanceof MessageListener) {
546546
this.logger.info(this);
547547
}
548548
Map<String, Object> props = KafkaMessageListenerContainer.this.consumerFactory.getConfigurationProperties();
549-
this.checkNullKeyForExceptions = checkDeserializer(
550-
findDeserializerClass(props, ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG));
551-
this.checkNullValueForExceptions = checkDeserializer(
552-
findDeserializerClass(props, ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG));
549+
this.checkNullKeyForExceptions = checkDeserializer(findDeserializerClass(props, false));
550+
this.checkNullValueForExceptions = checkDeserializer(findDeserializerClass(props, true));
553551
}
554552

555-
private Object findDeserializerClass(Map<String, Object> props, String config) {
556-
Object configuredDeserializer = KafkaMessageListenerContainer.this.consumerFactory.getKeyDeserializer();
553+
private Object findDeserializerClass(Map<String, Object> props, boolean isValue) {
554+
Object configuredDeserializer = isValue
555+
? KafkaMessageListenerContainer.this.consumerFactory.getValueDeserializer()
556+
: KafkaMessageListenerContainer.this.consumerFactory.getKeyDeserializer();
557557
if (configuredDeserializer == null) {
558-
return props.get(config);
558+
return props.get(isValue
559+
? ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG
560+
: ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG);
559561
}
560562
else {
561563
return configuredDeserializer.getClass();

0 commit comments

Comments
 (0)