Skip to content

Commit a067eaa

Browse files
authored
GH-2736: Fix Possible Observation NPEs
Resolves #2736
1 parent f079ed3 commit a067eaa

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

spring-kafka/src/main/java/org/springframework/kafka/support/micrometer/KafkaRecordReceiverContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 the original author or authors.
2+
* Copyright 2022-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,7 +40,7 @@ public class KafkaRecordReceiverContext extends ReceiverContext<ConsumerRecord<?
4040
public KafkaRecordReceiverContext(ConsumerRecord<?, ?> record, String listenerId, Supplier<String> clusterId) {
4141
super((carrier, key) -> {
4242
Header header = carrier.headers().lastHeader(key);
43-
if (header == null) {
43+
if (header == null || header.value() == null) {
4444
return null;
4545
}
4646
return new String(header.value(), StandardCharsets.UTF_8);

spring-kafka/src/main/java/org/springframework/kafka/support/micrometer/KafkaRecordSenderContext.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 the original author or authors.
2+
* Copyright 2022-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,7 +37,8 @@ public class KafkaRecordSenderContext extends SenderContext<ProducerRecord<?, ?>
3737
private final ProducerRecord<?, ?> record;
3838

3939
public KafkaRecordSenderContext(ProducerRecord<?, ?> record, String beanName, Supplier<String> clusterId) {
40-
super((carrier, key, value) -> record.headers().add(key, value.getBytes(StandardCharsets.UTF_8)));
40+
super((carrier, key, value) -> record.headers().add(key,
41+
value == null ? null : value.getBytes(StandardCharsets.UTF_8)));
4142
setCarrier(record);
4243
this.beanName = beanName;
4344
this.record = record;

0 commit comments

Comments
 (0)