Skip to content

Commit 9876db3

Browse files
authored
Add JSpecify nullify to channel/interceptor, and codec/kryo packages
Continued effort or issue: #10083 * Missed the channel/interceptor on the last PR. * Removed @nullable from delegates field in CompositeCodec * Remove check for null for delegate and replace it with isEmpty * Remove @nullable from delegates param in the ctor
1 parent f4670e5 commit 9876db3

File tree

7 files changed

+24
-13
lines changed

7 files changed

+24
-13
lines changed

spring-integration-core/src/main/java/org/springframework/integration/channel/interceptor/WireTap.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.apache.commons.logging.Log;
2020
import org.apache.commons.logging.LogFactory;
21+
import org.jspecify.annotations.Nullable;
2122

2223
import org.springframework.beans.BeansException;
2324
import org.springframework.beans.factory.BeanFactory;
@@ -50,16 +51,19 @@ public class WireTap implements ChannelInterceptor, ManageableLifecycle, VetoCap
5051

5152
private static final Log LOGGER = LogFactory.getLog(WireTap.class);
5253

53-
private final MessageSelector selector;
54+
private final @Nullable MessageSelector selector;
5455

56+
@SuppressWarnings("NullAway.Init")
5557
private MessageChannel channel;
5658

57-
private String channelName;
59+
private @Nullable String channelName;
5860

5961
private long timeout = 0;
6062

63+
@SuppressWarnings("NullAway.Init")
6164
private BeanFactory beanFactory;
6265

66+
@SuppressWarnings("NullAway.Init")
6367
private MessageBuilderFactory messageBuilderFactory;
6468

6569
private volatile boolean running = true;
@@ -78,7 +82,7 @@ public WireTap(MessageChannel channel) {
7882
* @param selector the selector that must accept a message for it to be
7983
* sent to the intercepting channel
8084
*/
81-
public WireTap(MessageChannel channel, MessageSelector selector) {
85+
public WireTap(MessageChannel channel, @Nullable MessageSelector selector) {
8286
Assert.notNull(channel, "channel must not be null");
8387
this.channel = channel;
8488
this.selector = selector;
@@ -103,7 +107,7 @@ public WireTap(String channelName) {
103107
* sent to the intercepting channel
104108
* @since 4.3
105109
*/
106-
public WireTap(String channelName, MessageSelector selector) {
110+
public WireTap(String channelName, @Nullable MessageSelector selector) {
107111
Assert.hasText(channelName, "channelName must not be empty");
108112
this.channelName = channelName;
109113
this.selector = selector;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/**
22
* Provides classes related to channel interception.
33
*/
4+
@org.jspecify.annotations.NullMarked
45
package org.springframework.integration.channel.interceptor;

spring-integration-core/src/main/java/org/springframework/integration/codec/CodecMessageConverter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.io.IOException;
2020

21+
import org.jspecify.annotations.Nullable;
22+
2123
import org.springframework.integration.context.IntegrationObjectSupport;
2224
import org.springframework.integration.support.AbstractIntegrationMessageBuilder;
2325
import org.springframework.messaging.Message;
@@ -57,7 +59,7 @@ public Object fromMessage(Message<?> message, Class<?> targetClass) {
5759
}
5860

5961
@Override
60-
public Message<?> toMessage(Object payload, MessageHeaders headers) {
62+
public Message<?> toMessage(Object payload, @Nullable MessageHeaders headers) {
6163
Assert.isInstanceOf(byte[].class, payload);
6264
try {
6365
Message<?> decoded = (Message<?>) this.codec.decode((byte[]) payload, this.messageClass);

spring-integration-core/src/main/java/org/springframework/integration/codec/CompositeCodec.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.util.HashMap;
2424
import java.util.Map;
2525

26+
import org.jspecify.annotations.Nullable;
27+
2628
import org.springframework.integration.util.ClassUtils;
2729
import org.springframework.util.Assert;
2830

@@ -38,13 +40,12 @@ public class CompositeCodec implements Codec {
3840
private final Map<Class<?>, Codec> delegates;
3941

4042
public CompositeCodec(Map<Class<?>, Codec> delegates, Codec defaultCodec) {
41-
Assert.notNull(defaultCodec, "'defaultCodec' cannot be null");
4243
this.defaultCodec = defaultCodec;
4344
this.delegates = new HashMap<Class<?>, Codec>(delegates);
4445
}
4546

4647
public CompositeCodec(Codec defaultCodec) {
47-
this(null, defaultCodec);
48+
this(Map.of(), defaultCodec);
4849
}
4950

5051
@Override
@@ -90,8 +91,8 @@ public <T> T decode(byte[] bytes, Class<T> type) throws IOException {
9091
return decode(new ByteArrayInputStream(bytes), type);
9192
}
9293

93-
private Codec findDelegate(Class<?> type) {
94-
if (this.delegates == null) {
94+
private @Nullable Codec findDelegate(Class<?> type) {
95+
if (this.delegates.isEmpty()) {
9596
return null;
9697
}
9798

spring-integration-core/src/main/java/org/springframework/integration/codec/kryo/PojoCodec.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.esotericsoftware.kryo.io.Input;
2424
import com.esotericsoftware.kryo.io.Output;
2525
import com.esotericsoftware.kryo.util.DefaultInstantiatorStrategy;
26+
import org.jspecify.annotations.Nullable;
2627
import org.objenesis.strategy.StdInstantiatorStrategy;
2728

2829
import org.springframework.util.CollectionUtils;
@@ -39,7 +40,7 @@
3940
*/
4041
public class PojoCodec extends AbstractKryoCodec {
4142

42-
private final CompositeKryoRegistrar kryoRegistrar;
43+
private final @Nullable CompositeKryoRegistrar kryoRegistrar;
4344

4445
private final boolean useReferences;
4546

@@ -52,7 +53,7 @@ public PojoCodec() {
5253
* Create an instance with a single KryoRegistrar.
5354
* @param kryoRegistrar the registrar.
5455
*/
55-
public PojoCodec(KryoRegistrar kryoRegistrar) {
56+
public PojoCodec(@Nullable KryoRegistrar kryoRegistrar) {
5657
this(kryoRegistrar != null ? Collections.singletonList(kryoRegistrar) : null, true);
5758
}
5859

@@ -72,7 +73,7 @@ public PojoCodec(List<KryoRegistrar> kryoRegistrars) {
7273
* @param useReferences set to false if references are not required (if the object graph is known to be acyclical).
7374
* The default is 'true' which is less performant but more flexible.
7475
*/
75-
public PojoCodec(KryoRegistrar kryoRegistrar, boolean useReferences) {
76+
public PojoCodec(@Nullable KryoRegistrar kryoRegistrar, boolean useReferences) {
7677
this(kryoRegistrar != null ? Collections.singletonList(kryoRegistrar) : null, useReferences);
7778
}
7879

@@ -82,7 +83,7 @@ public PojoCodec(KryoRegistrar kryoRegistrar, boolean useReferences) {
8283
* @param useReferences set to false if references are not required (if the object graph is known to be acyclical).
8384
* The default is 'true' which is less performant but more flexible.
8485
*/
85-
public PojoCodec(List<KryoRegistrar> kryoRegistrars, boolean useReferences) {
86+
public PojoCodec(@Nullable List<KryoRegistrar> kryoRegistrars, boolean useReferences) {
8687
this.kryoRegistrar = CollectionUtils.isEmpty(kryoRegistrars) ? null :
8788
new CompositeKryoRegistrar(kryoRegistrars);
8889
this.useReferences = useReferences;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/**
22
* The <a href="https://code.google.com/p/kryo/">Kryo</a> specific {@code Codec} classes.
33
*/
4+
@org.jspecify.annotations.NullMarked
45
package org.springframework.integration.codec.kryo;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/**
22
* Provides base classes for the {@code Codec} abstraction.
33
*/
4+
@org.jspecify.annotations.NullMarked
45
package org.springframework.integration.codec;

0 commit comments

Comments
 (0)