From d08a0978c948702ebe3bae8dcf7660850b0d9c08 Mon Sep 17 00:00:00 2001 From: zhaochun-ma <100243733+zhaochun-ma@users.noreply.github.com> Date: Tue, 23 Jan 2024 17:06:35 -0500 Subject: [PATCH] fix NPE when value is nil when print.schema.ids=true is set --- .../confluent/kafka/formatter/SchemaMessageFormatter.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/schema-serializer/src/main/java/io/confluent/kafka/formatter/SchemaMessageFormatter.java b/schema-serializer/src/main/java/io/confluent/kafka/formatter/SchemaMessageFormatter.java index 917a1118d9a..379bb767ab4 100644 --- a/schema-serializer/src/main/java/io/confluent/kafka/formatter/SchemaMessageFormatter.java +++ b/schema-serializer/src/main/java/io/confluent/kafka/formatter/SchemaMessageFormatter.java @@ -185,8 +185,12 @@ public void writeTo(ConsumerRecord consumerRecord, PrintStream o writeTo(consumerRecord.topic(), consumerRecord.value(), output); if (printValueId) { output.write(idSeparator); - int schemaId = schemaIdFor(consumerRecord.value()); - output.print(schemaId); + if (consumerRecord.value() != null) { + int schemaId = schemaIdFor(consumerRecord.value()); + output.print(schemaId); + } else { + output.write(NULL_BYTES); + } } output.write(lineSeparator); } catch (IOException ioe) {