In what version(s) of Spring for Apache Kafka are you seeing this issue?
Since 4.0.0
Describe the bug
The ProducerFactory and ConsumerFactory interface type parameters do not allow instantiating implementing classes with nullable types when using Kotlin. For example the following Kotlin code to create a producer that allows sending tombstones does not compile:
val properties = mapOf(...)
val producer = DefaultKafkaProducerFactory<String, String?>(properties).createProducer()
This is an issue because now the factory has a nullability specification (non-nullable) while the producer/consumer created by the factory still allows sending/consuming tombstones.
We encountered this issue while implementing a KafkaTestUtilities class and we created a sample project to reproduce it here. Each following step is represented in a dedicated commit.
To Reproduce
See sample project and follow along the three commits.
Expected behavior
ProducerFactory and ConsumerFactory and their implementations should allow nullable type parameters, i.e.
public interface ProducerFactory<K, V extends @Nullable Object> { ... }
public interface ConsumerFactory<K, V extends @Nullable Object> { ... }
This would allow the Step 2 commit in the reproducible sample to compile and execute all tests successfully.
Sample
https://github.com/denniseffing/spring-kafka-nullability-issues
In what version(s) of Spring for Apache Kafka are you seeing this issue?
Since 4.0.0
Describe the bug
The
ProducerFactoryandConsumerFactoryinterface type parameters do not allow instantiating implementing classes with nullable types when using Kotlin. For example the following Kotlin code to create a producer that allows sending tombstones does not compile:This is an issue because now the factory has a nullability specification (non-nullable) while the producer/consumer created by the factory still allows sending/consuming tombstones.
We encountered this issue while implementing a
KafkaTestUtilitiesclass and we created a sample project to reproduce it here. Each following step is represented in a dedicated commit.NullPointerException: denniseffing/spring-kafka-nullability-issues@86ce5c54:src/test/kotlin/com/example/kafka_nullability_issues/ReproducingNullabilityIssueTest.kt#28-37To Reproduce
See sample project and follow along the three commits.
Expected behavior
ProducerFactoryandConsumerFactoryand their implementations should allow nullable type parameters, i.e.This would allow the Step 2 commit in the reproducible sample to compile and execute all tests successfully.
Sample
https://github.com/denniseffing/spring-kafka-nullability-issues