File tree Expand file tree Collapse file tree 2 files changed +23
-4
lines changed
main/java/org/springframework/kafka/support
test/java/org/springframework/kafka/support Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Original file line number Diff line number Diff line change 43
43
*
44
44
* @author Gary Russell
45
45
* @author Artem Bilan
46
+ * @author Soby Chacko
46
47
*
47
48
* @since 2.1.3
48
49
*
@@ -267,11 +268,11 @@ else if (value instanceof String) {
267
268
* @return the value to add.
268
269
*/
269
270
protected Object headerValueToAddIn (Header header ) {
270
- Object mapped = mapRawIn (header .key (), header .value ());
271
- if (mapped == null ) {
272
- mapped = header .value ();
271
+ if (header == null || header .value () == null ) {
272
+ return null ;
273
273
}
274
- return mapped ;
274
+ String mapped = mapRawIn (header .key (), header .value ());
275
+ return mapped != null ? mapped : header .value ();
275
276
}
276
277
277
278
@ Nullable
Original file line number Diff line number Diff line change 47
47
48
48
import static org .assertj .core .api .Assertions .assertThat ;
49
49
import static org .assertj .core .api .Assertions .entry ;
50
+ import static org .mockito .BDDMockito .given ;
51
+ import static org .mockito .Mockito .mock ;
52
+ import static org .mockito .Mockito .never ;
53
+ import static org .mockito .Mockito .verify ;
50
54
51
55
/**
52
56
* @author Gary Russell
@@ -360,6 +364,20 @@ void deserializationExceptionHeadersAreMappedAsNonByteArray() {
360
364
assertThat (headers .lastHeader (SerializationUtils .VALUE_DESERIALIZER_EXCEPTION_HEADER )).isNull ();
361
365
}
362
366
367
+ @ Test
368
+ void ensureNullHeaderValueHandledGraciously () {
369
+ DefaultKafkaHeaderMapper mapper = new DefaultKafkaHeaderMapper ();
370
+
371
+ Header mockHeader = mock (Header .class );
372
+ given (mockHeader .value ()).willReturn (null );
373
+
374
+ Object result = mapper .headerValueToAddIn (mockHeader );
375
+
376
+ assertThat (result ).isNull ();
377
+ verify (mockHeader ).value ();
378
+ verify (mockHeader , never ()).key ();
379
+ }
380
+
363
381
public static final class Foo {
364
382
365
383
private String bar = "bar" ;
You can’t perform that action at this time.
0 commit comments