1
1
/*
2
- * Copyright 2018-2023 the original author or authors.
2
+ * Copyright 2018-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
21
21
22
22
import org .apache .kafka .common .header .Headers ;
23
23
import org .apache .kafka .common .serialization .Deserializer ;
24
+ import org .jspecify .annotations .Nullable ;
24
25
25
26
import org .springframework .util .Assert ;
26
27
import org .springframework .util .ClassUtils ;
@@ -66,13 +67,13 @@ public class ErrorHandlingDeserializer<T> implements Deserializer<T> {
66
67
*/
67
68
public static final String VALIDATOR_CLASS = "spring.deserializer.validator.class" ;
68
69
69
- private Deserializer <T > delegate ;
70
+ private @ Nullable Deserializer <T > delegate ;
70
71
71
72
private boolean isForKey ;
72
73
73
- private Function <FailedDeserializationInfo , T > failedDeserializationFunction ;
74
+ private @ Nullable Function <FailedDeserializationInfo , T > failedDeserializationFunction ;
74
75
75
- private Validator validator ;
76
+ private @ Nullable Validator validator ;
76
77
77
78
public ErrorHandlingDeserializer () {
78
79
}
@@ -194,25 +195,25 @@ private void setupValidator(Map<String, ?> configs) {
194
195
}
195
196
196
197
@ Override
197
- public T deserialize (String topic , byte [] data ) {
198
+ public @ Nullable T deserialize (String topic , byte [] data ) {
198
199
try {
199
- return validate (this .delegate .deserialize (topic , data ));
200
+ return this . delegate == null ? null : validate (this .delegate .deserialize (topic , data ));
200
201
}
201
202
catch (Exception e ) {
202
203
return recoverFromSupplier (topic , null , data , e );
203
204
}
204
205
}
205
206
206
207
@ Override
207
- public T deserialize (String topic , Headers headers , byte [] data ) {
208
+ public @ Nullable T deserialize (String topic , Headers headers , byte [] data ) {
208
209
try {
209
210
if (this .isForKey ) {
210
211
headers .remove (SerializationUtils .KEY_DESERIALIZER_EXCEPTION_HEADER );
211
212
}
212
213
else {
213
214
headers .remove (SerializationUtils .VALUE_DESERIALIZER_EXCEPTION_HEADER );
214
215
}
215
- return validate (this .delegate .deserialize (topic , headers , data ));
216
+ return this . delegate == null ? null : validate (this .delegate .deserialize (topic , headers , data ));
216
217
}
217
218
catch (Exception e ) {
218
219
SerializationUtils .deserializationException (headers , data , e , this .isForKey );
@@ -228,7 +229,7 @@ private T validate(T deserialized) {
228
229
return deserialized ;
229
230
}
230
231
231
- private T recoverFromSupplier (String topic , Headers headers , byte [] data , Exception exception ) {
232
+ private @ Nullable T recoverFromSupplier (String topic , @ Nullable Headers headers , byte [] data , Exception exception ) {
232
233
if (this .failedDeserializationFunction != null ) {
233
234
FailedDeserializationInfo failedDeserializationInfo =
234
235
new FailedDeserializationInfo (topic , headers , data , this .isForKey , exception );
0 commit comments