KStreamListenerParameterAdapter crashes with NPE on Kafka tombstones records
See original GitHub issueRecently I’ve been working with a Kafka Connect connector (Debezium Mongo) which by default is utilising the Kafka topic compaction, it was not a desired behaviour for my use case so I’ve submitted a PR to their repository (worth checking as it will show how I got to the error I’m about to describe https://github.com/debezium/debezium/pull/421)
The problem is that KStreamListenerParameterAdapter will not handle kafka tombstones records properly and it will crash with NullPointerException when it tries to consume a kafka message which is a tombstone.
return bindingTarget.map(new KeyValueMapper() {
@Override
public Object apply(Object o, Object o2) {
if (valueClass.isAssignableFrom(o2.getClass())) {
return new KeyValue<>(o, o2);
}
the o2.getClass() will generate NPE
Here is the snapshot from the topic, first message is a delete operation, the second one is the tombstone null associated (and generated) with this delete message.

And here’s where the explosion is about to happen:

Detected in:
package: org.springframework.cloud.stream.binder.kstream
class: KStreamListenerParameterAdapter
maven co-ords to the jar: org.springframework.cloud:spring-cloud-stream-binder-kstream11:1.3.0.RELEASE
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (4 by maintainers)

Top Related StackOverflow Question
@rliwoch Thanks for reporting this. It looks like this is a bug. We will filter out null values in the adapter as you cannot do any stream processing on that anyway. Will try to fix it in the 2.0 timeline. Any further feedback or better yet contributions are welcomed! Thank you.
This issue was moved to spring-cloud/spring-cloud-stream-binder-kafka#294