Skip to content

Commit 85aa161

Browse files
committed
More jspecify nullability changes in support package
#3762 Signed-off-by: Soby Chacko <[email protected]>
1 parent e5907af commit 85aa161

22 files changed

+72
-53
lines changed

spring-kafka/src/main/java/org/springframework/kafka/config/AbstractKafkaListenerContainerFactory.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public void setThreadNameSupplier(Function<MessageListenerContainer, String> thr
350350
this.threadNameSupplier = threadNameSupplier;
351351
}
352352

353-
@SuppressWarnings("unchecked")
353+
@SuppressWarnings({"unchecked", "NullAway"})
354354
@Override
355355
public C createListenerContainer(KafkaListenerEndpoint endpoint) {
356356
C instance = createContainerInstance(endpoint);
@@ -372,6 +372,7 @@ public C createListenerContainer(KafkaListenerEndpoint endpoint) {
372372
return instance;
373373
}
374374

375+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
375376
private void configureEndpoint(AbstractKafkaListenerEndpoint<K, V> aklEndpoint) {
376377
if (aklEndpoint.getRecordFilterStrategy() == null) {
377378
JavaUtils.INSTANCE
@@ -403,7 +404,7 @@ private void configureEndpoint(AbstractKafkaListenerEndpoint<K, V> aklEndpoint)
403404
* @param instance the container instance to configure.
404405
* @param endpoint the endpoint.
405406
*/
406-
@SuppressWarnings("deprecation")
407+
@SuppressWarnings({"deprecation", "NullAway"})
407408
protected void initializeContainer(C instance, KafkaListenerEndpoint endpoint) {
408409
ContainerProperties properties = instance.getContainerProperties();
409410
BeanUtils.copyProperties(this.containerProperties, properties, "topics", "topicPartitions", "topicPattern",

spring-kafka/src/main/java/org/springframework/kafka/config/AbstractKafkaListenerEndpoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ public void setupListenerContainer(MessageListenerContainer listenerContainer,
525525
protected abstract MessagingMessageListenerAdapter<K, V> createMessageListener(MessageListenerContainer container,
526526
@Nullable MessageConverter messageConverter);
527527

528-
@SuppressWarnings("unchecked")
528+
@SuppressWarnings({"unchecked", "NullAway"})
529529
private void setupMessageListener(MessageListenerContainer container,
530530
@Nullable MessageConverter messageConverter) {
531531

spring-kafka/src/main/java/org/springframework/kafka/config/KafkaListenerEndpointRegistry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,9 @@ public MessageListenerContainer unregisterListenerContainer(String id) {
318318
* @param factory the {@link KafkaListenerContainerFactory} to use.
319319
* @return the {@link MessageListenerContainer}.
320320
*/
321+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
321322
protected MessageListenerContainer createListenerContainer(KafkaListenerEndpoint endpoint,
322323
KafkaListenerContainerFactory<?> factory) {
323-
324324
if (endpoint instanceof MultiMethodKafkaListenerEndpoint<?, ?> mmkle) {
325325
Object bean = mmkle.getBean();
326326
if (bean instanceof EndpointHandlerMultiMethod ehmm) {

spring-kafka/src/main/java/org/springframework/kafka/config/MethodKafkaListenerEndpoint.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ public void setMessagingConverter(SmartMessageConverter messagingConverter) {
131131
this.messagingConverter = messagingConverter;
132132
}
133133

134-
@Nullable
135-
private String getReplyTopic() {
134+
private @Nullable String getReplyTopic() {
136135
Method replyingMethod = getMethod();
137136
if (replyingMethod != null) {
138137
SendTo ann = AnnotatedElementUtils.findMergedAnnotation(replyingMethod, SendTo.class);
@@ -171,6 +170,7 @@ private String getReplyTopic() {
171170
}
172171

173172
@Override
173+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
174174
protected MessagingMessageListenerAdapter<K, V> createMessageListener(MessageListenerContainer container,
175175
@Nullable MessageConverter messageConverter) {
176176

spring-kafka/src/main/java/org/springframework/kafka/support/AbstractKafkaHeaderMapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ protected Object headerValueToAddOut(String key, Object value) {
251251
return valueToAdd;
252252
}
253253

254+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
254255
@Nullable
255256
private byte[] mapRawOut(String header, Object value) {
256257
if (this.mapAllStringsOut || this.rawMappedHeaders.containsKey(header)) {
@@ -269,7 +270,7 @@ else if (value instanceof String) {
269270
* @param header the header.
270271
* @return the value to add.
271272
*/
272-
protected Object headerValueToAddIn(Header header) {
273+
protected @Nullable Object headerValueToAddIn(@Nullable Header header) {
273274
if (header == null || header.value() == null) {
274275
return null;
275276
}

spring-kafka/src/main/java/org/springframework/kafka/support/CompositeProducerListener.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2020 the original author or authors.
2+
* Copyright 2018-2025 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.
@@ -22,6 +22,7 @@
2222

2323
import org.apache.kafka.clients.producer.ProducerRecord;
2424
import org.apache.kafka.clients.producer.RecordMetadata;
25+
import org.jspecify.annotations.Nullable;
2526

2627
import org.springframework.util.Assert;
2728

@@ -74,7 +75,7 @@ public void onSuccess(ProducerRecord<K, V> producerRecord, RecordMetadata record
7475
}
7576

7677
@Override
77-
public void onError(ProducerRecord<K, V> producerRecord, RecordMetadata recordMetadata, Exception exception) {
78+
public void onError(ProducerRecord<K, V> producerRecord, @Nullable RecordMetadata recordMetadata, Exception exception) {
7879
this.delegates.forEach(d -> d.onError(producerRecord, recordMetadata, exception));
7980
}
8081

spring-kafka/src/main/java/org/springframework/kafka/support/DefaultKafkaHeaderMapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2024 the original author or authors.
2+
* Copyright 2017-2025 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.
@@ -430,6 +430,7 @@ public static class NonTrustedHeaderType {
430430

431431
private String untrustedType;
432432

433+
@SuppressWarnings("NullAway.Init")
433434
public NonTrustedHeaderType() {
434435
}
435436

spring-kafka/src/main/java/org/springframework/kafka/support/EndpointHandlerMethod.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2024 the original author or authors.
2+
* Copyright 2021-2025 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.
@@ -19,6 +19,8 @@
1919
import java.lang.reflect.Method;
2020
import java.util.Arrays;
2121

22+
import org.jspecify.annotations.Nullable;
23+
2224
import org.springframework.beans.factory.BeanCurrentlyInCreationException;
2325
import org.springframework.beans.factory.BeanFactory;
2426
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
@@ -41,11 +43,11 @@ public class EndpointHandlerMethod {
4143

4244
private final Object beanOrClass;
4345

44-
private String methodName;
46+
private @Nullable String methodName;
4547

46-
private Object bean;
48+
private @Nullable Object bean;
4749

48-
private Method method;
50+
private @Nullable Method method;
4951

5052
public EndpointHandlerMethod(Object beanOrClass, String methodName) {
5153
Assert.notNull(beanOrClass, () -> "No destination bean or class provided!");

spring-kafka/src/main/java/org/springframework/kafka/support/JacksonPresent.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2019 the original author or authors.
2+
* Copyright 2017-2025 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.
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.kafka.support;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
import org.springframework.util.ClassUtils;
2022

2123
/**
@@ -28,7 +30,7 @@
2830
*/
2931
public final class JacksonPresent {
3032

31-
private static final ClassLoader classLoader = ClassUtils.getDefaultClassLoader(); // NOSONAR
33+
private static final @Nullable ClassLoader classLoader = ClassUtils.getDefaultClassLoader(); // NOSONAR
3234

3335
private static final boolean jackson2Present = // NOSONAR
3436
ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", classLoader) &&

spring-kafka/src/main/java/org/springframework/kafka/support/JavaUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public <T> JavaUtils acceptIfCondition(boolean condition, T value, Consumer<T> c
6868
* @param <T> the value type.
6969
* @return this.
7070
*/
71-
public <T> JavaUtils acceptIfNotNull(@Nullable T value, Consumer<T> consumer) {
71+
public <T> JavaUtils acceptIfNotNull(@Nullable T value, Consumer<@Nullable T> consumer) {
7272
if (value != null) {
7373
consumer.accept(value);
7474
}
@@ -162,7 +162,7 @@ public <T1, T2> JavaUtils acceptIfCondition(boolean condition, T1 t1, T2 t2, BiC
162162
* @param <T2> the second argument type.
163163
* @return this.
164164
*/
165-
public <T1, T2> JavaUtils acceptIfNotNull(T1 t1, T2 t2, BiConsumer<T1, T2> consumer) {
165+
public <T1, T2> JavaUtils acceptIfNotNull(T1 t1, @Nullable T2 t2, BiConsumer<T1, @Nullable T2> consumer) {
166166
if (t2 != null) {
167167
consumer.accept(t1, t2);
168168
}

0 commit comments

Comments
 (0)