[ https://issues.apache.org/jira/browse/FLINK-8544?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16541534#comment-16541534
]
ASF GitHub Bot commented on FLINK-8544:
---------------------------------------
Github user dawidwys commented on the issue:
https://github.com/apache/flink/pull/5516
Hi @BillLeecn
Thank you for the contribution!
Would you mind adding guard against null messages as well? Other than that it looks good.
> JSONKeyValueDeserializationSchema throws NPE when message key is null
> ---------------------------------------------------------------------
>
> Key: FLINK-8544
> URL: https://issues.apache.org/jira/browse/FLINK-8544
> Project: Flink
> Issue Type: Bug
> Components: Kafka Connector
> Affects Versions: 1.4.0
> Reporter: Bill Lee
> Priority: Major
> Labels: pull-request-available
> Original Estimate: 1h
> Remaining Estimate: 1h
>
> JSONKeyValueDeserializationSchema call Jaskon to deserialize the message key without
validation.
> If a message with key == null is read, flink throws an NPE.
> {code:java}
> @Override
> public ObjectNode deserialize(byte[] messageKey, byte[] message, String topic, int partition,
long offset) throws IOException {
> if (mapper == null) {
> mapper = new ObjectMapper();
> }
> ObjectNode node = mapper.createObjectNode();
> node.set("key", mapper.readValue(messageKey, JsonNode.class)); // messageKey is not
validate against null.
> node.set("value", mapper.readValue(message, JsonNode.class));
> {code}
> The fix is very straightforward.
> {code:java}
> if (messageKey == null) {
> node.set("key", null)
> } else {
> node.set("key", mapper.readValue(messageKey, JsonNode.class));
> }
> {code}
> If it is appreciated, I would send a pull request.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
|