Skip to content

Missing JSpecify @Nullable annotation for consumer & producer factories #4355

Description

@denniseffing

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions