Skip to content

Commit 4a105e5

Browse files
committed
jspecify nullability changes for the streams package
Signed-off-by: Soby Chacko <[email protected]>
1 parent ea9cf27 commit 4a105e5

File tree

6 files changed

+17
-7
lines changed

6 files changed

+17
-7
lines changed

Diff for: spring-kafka/src/main/java/org/springframework/kafka/streams/HeaderEnricherProcessor.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 the original author or authors.
2+
* Copyright 2019-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.
@@ -60,7 +60,12 @@ public void process(Record<K, V> record) {
6060
headerValue = ((String) headerValue).getBytes(StandardCharsets.UTF_8);
6161
}
6262
else if (!(headerValue instanceof byte[])) {
63-
throw new IllegalStateException("Invalid header value type: " + headerValue.getClass());
63+
if (headerValue != null) {
64+
throw new IllegalStateException("Invalid header value type: " + headerValue.getClass());
65+
}
66+
else {
67+
throw new IllegalStateException("headerValue is null");
68+
}
6469
}
6570
headers.add(new RecordHeader(name, (byte[]) headerValue));
6671
});

Diff for: spring-kafka/src/main/java/org/springframework/kafka/streams/KafkaStreamsInteractiveQueryService.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class KafkaStreamsInteractiveQueryService {
5454
/**
5555
* Underlying {@link KafkaStreams} from {@link StreamsBuilderFactoryBean}.
5656
*/
57-
private volatile KafkaStreams kafkaStreams;
57+
private volatile @Nullable KafkaStreams kafkaStreams;
5858

5959
/**
6060
* Construct an instance for querying state stores from the KafkaStreams in the {@link StreamsBuilderFactoryBean}.
@@ -87,6 +87,7 @@ public <T> T retrieveQueryableStore(String storeName, QueryableStoreType<T> stor
8787

8888
return this.retryTemplate.execute(context -> {
8989
try {
90+
Assert.state(this.kafkaStreams != null, "KafkaStreams cannot be null.");
9091
return this.kafkaStreams.store(storeQueryParams);
9192
}
9293
catch (Exception e) {
@@ -143,6 +144,7 @@ public <K> HostInfo getKafkaStreamsApplicationHostInfo(String store, K key, Seri
143144
return this.retryTemplate.execute(context -> {
144145
Throwable throwable = null;
145146
try {
147+
Assert.state(this.kafkaStreams != null, "KafkaStreams cannot be null.");
146148
KeyQueryMetadata keyQueryMetadata = this.kafkaStreams.queryMetadataForKey(store, key, serializer);
147149
if (keyQueryMetadata != null) {
148150
return keyQueryMetadata.activeHost();

Diff for: spring-kafka/src/main/java/org/springframework/kafka/streams/RecoveringDeserializationExceptionHandler.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 the original author or authors.
2+
* Copyright 2019-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.
@@ -24,6 +24,7 @@
2424
import org.apache.kafka.clients.consumer.ConsumerRecord;
2525
import org.apache.kafka.streams.errors.DeserializationExceptionHandler;
2626
import org.apache.kafka.streams.processor.ProcessorContext;
27+
import org.jspecify.annotations.Nullable;
2728

2829
import org.springframework.kafka.listener.ConsumerRecordRecoverer;
2930
import org.springframework.util.ClassUtils;
@@ -45,7 +46,7 @@ public class RecoveringDeserializationExceptionHandler implements Deserializatio
4546

4647
private static final Log LOGGER = LogFactory.getLog(RecoveringDeserializationExceptionHandler.class);
4748

48-
private ConsumerRecordRecoverer recoverer;
49+
private @Nullable ConsumerRecordRecoverer recoverer;
4950

5051
public RecoveringDeserializationExceptionHandler() {
5152
}

Diff for: spring-kafka/src/main/java/org/springframework/kafka/streams/messaging/MessagingProcessor.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 the original author or authors.
2+
* Copyright 2019-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.
@@ -84,7 +84,7 @@ public void process(Record<Kin, Vin> record) {
8484
message = this.function.exchange(message);
8585
List<String> headerList = new ArrayList<>();
8686
headers.forEach(header -> headerList.add(header.key()));
87-
headerList.forEach(name -> headers.remove(name));
87+
headerList.forEach(headers::remove);
8888
ProducerRecord<?, ?> fromMessage = this.converter.fromMessage(message, "dummy");
8989
fromMessage.headers().forEach(header -> {
9090
if (!header.key().equals(KafkaHeaders.TOPIC)) {
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/**
22
* Package for classes related to spring-messaging with Kafka Streams.
33
*/
4+
@org.jspecify.annotations.NullMarked
45
package org.springframework.kafka.streams.messaging;
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/**
22
* Package for classes related to Kafka Streams.
33
*/
4+
@org.jspecify.annotations.NullMarked
45
package org.springframework.kafka.streams;

0 commit comments

Comments
 (0)