[KAFKA-227] NullPointerException when returning null from a custom WriteModelStrategy Created: 27/May/21  Updated: 28/Oct/23  Resolved: 01/Jun/21

Status: Closed
Project: Kafka Connector
Component/s: Sink
Affects Version/s: 1.5.0
Fix Version/s: 1.5.1

Type: Bug Priority: Unknown
Reporter: Diego Díez Assignee: Ross Lawley
Resolution: Fixed Votes: 0
Labels: external-user
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Returning null from a custom WriteModelStrategy (as documented in https://docs.mongodb.com/kafka-connector/current/kafka-sink-postprocessors/#:~:text=Return%20null%20to%20indicate%20no%20op) throws a NullPointerException when trying to wrap the returned value in a java.util.Optional.

 

The fix seems trivial: Use Optional.ofNullable(value) instead of Optional.of(value)

https://github.com/mongodb/mongo-kafka/blob/122cfbe5e7fb7b1949e7f2d1298e1e0c540e6a5d/src/main/java/com/mongodb/kafka/connect/sink/MongoProcessedSinkRecordData.java#L91



 Comments   
Comment by Githook User [ 28/May/21 ]

Author:

{'name': 'Diego Díez', 'email': 'diegodiez.ddr@gmail.com', 'username': 'didiez'}

Message: Wrap nullable value returned from WriteModelStrategy using Optional.ofNullable(value)

KAFKA-227
Branch: 1.5.x
https://github.com/mongodb/mongo-kafka/commit/2f02129dfbc958fd12f77b05ac1be933965201b0

Comment by Githook User [ 28/May/21 ]

Author:

{'name': 'Diego Díez', 'email': 'diegodiez.ddr@gmail.com', 'username': 'didiez'}

Message: fixes KAFKA-227: Wrap nullable value returned from WriteModelStrategy using Optional.ofNullable(value)
Branch: 1.5.x
https://github.com/mongodb/mongo-kafka/commit/604ba2ad6c109878ab17c291e7a0f7036edaac65

Comment by Githook User [ 28/May/21 ]

Author:

{'name': 'Diego Díez', 'email': 'diegodiez.ddr@gmail.com', 'username': 'didiez'}

Message: fixes KAFKA-227: Wrap nullable value returned from WriteModelStrategy using Optional.ofNullable(value)
Branch: master
https://github.com/mongodb/mongo-kafka/commit/2fecd65974ce005d142464b2e658262d73784171

Comment by Diego Díez [ 27/May/21 ]

Great!

I forgot to comment here after sending the PR https://github.com/mongodb/mongo-kafka/pull/70 with the fix.

Comment by Ross Lawley [ 27/May/21 ]

Hi diegodiez.ddr@gmail.com,

Thanks for the ticket, this will be fixed in the next release.

Ross

Generated at Thu Feb 08 09:05:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.