Skip to content

Commit 6a60029

Browse files
committed
Apply JSpecify Nullify to the Channel and AOT packages
1 parent efb8860 commit 6a60029

File tree

20 files changed

+68
-50
lines changed

20 files changed

+68
-50
lines changed

spring-integration-amqp/src/main/java/org/springframework/integration/amqp/channel/PollableAmqpChannel.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Deque;
2121
import java.util.List;
2222
import java.util.Map;
23+
import java.util.Objects;
2324
import java.util.concurrent.atomic.AtomicBoolean;
2425

2526
import org.jspecify.annotations.Nullable;
@@ -322,12 +323,12 @@ public boolean removeInterceptor(ChannelInterceptor interceptor) {
322323
}
323324

324325
@Override
325-
public @Nullable ChannelInterceptor removeInterceptor(int index) {
326+
public ChannelInterceptor removeInterceptor(int index) {
326327
ChannelInterceptor interceptor = super.removeInterceptor(index);
327328
if (interceptor instanceof ExecutorChannelInterceptor) {
328329
this.executorInterceptorsSize--;
329330
}
330-
return interceptor;
331+
return Objects.requireNonNull(interceptor);
331332
}
332333

333334
@Override

spring-integration-core/src/main/java/org/springframework/integration/aot/CoreRuntimeHints.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import java.util.function.Supplier;
2727
import java.util.stream.Stream;
2828

29+
import org.jspecify.annotations.Nullable;
30+
2931
import org.springframework.aop.framework.AopProxyUtils;
3032
import org.springframework.aot.hint.ExecutableMode;
3133
import org.springframework.aot.hint.MemberCategory;
@@ -79,7 +81,7 @@
7981
class CoreRuntimeHints implements RuntimeHintsRegistrar {
8082

8183
@Override
82-
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
84+
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
8385
ReflectionHints reflectionHints = hints.reflection();
8486
Stream.of(
8587
GenericSelector.class,
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/**
22
* Provides classes to support Spring AOT.
33
*/
4-
@org.springframework.lang.NonNullApi
5-
@org.springframework.lang.NonNullFields
4+
@org.jspecify.annotations.NullMarked
65
package org.springframework.integration.aot;

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,19 @@
5959
public abstract class AbstractExecutorChannel extends AbstractSubscribableChannel
6060
implements ExecutorChannelInterceptorAware {
6161

62-
protected Executor executor; // NOSONAR
62+
protected @Nullable Executor executor;
6363

64-
protected AbstractDispatcher dispatcher; // NOSONAR
64+
/**
65+
* {@code @SuppressWarnings} was used the dispatcher is initialized in each of the implementations in the {@link AbstractExecutorChannel}. And each implementation
66+
* utilizes a unique implementation of the {@link AbstractDispatcher}.
67+
*/
68+
@SuppressWarnings("NullAway.Init")
69+
protected AbstractDispatcher dispatcher;
6570

66-
protected Integer maxSubscribers; // NOSONAR
71+
@Nullable
72+
protected Integer maxSubscribers;
6773

68-
protected int executorInterceptorsSize; // NOSONAR
74+
protected int executorInterceptorsSize;
6975

7076
public AbstractExecutorChannel(@Nullable Executor executor) {
7177
this.executor = executor;
@@ -117,7 +123,6 @@ public boolean removeInterceptor(ChannelInterceptor interceptor) {
117123
}
118124

119125
@Override
120-
@Nullable
121126
public ChannelInterceptor removeInterceptor(int index) {
122127
ChannelInterceptor interceptor = super.removeInterceptor(index);
123128
if (interceptor instanceof ExecutorChannelInterceptor) {
@@ -167,7 +172,7 @@ public void run() {
167172
if (!CollectionUtils.isEmpty(interceptorStack)) {
168173
triggerAfterMessageHandled(message, ex, interceptorStack);
169174
}
170-
if (ex instanceof MessagingException) { // NOSONAR
175+
if (ex instanceof MessagingException) {
171176
throw new MessagingExceptionWrapper(message, (MessagingException) ex);
172177
}
173178
String description = "Failed to handle " + message + " to " + this + " in " + messageHandler;
@@ -195,7 +200,7 @@ private Message<?> applyBeforeHandle(Message<?> message, Deque<ExecutorChannelIn
195200
logger.debug(() -> executorInterceptor.getClass().getSimpleName()
196201
+ " returned null from beforeHandle, i.e. precluding the send.");
197202
}
198-
triggerAfterMessageHandled(null, null, interceptorStack);
203+
triggerAfterMessageHandled(message, null, interceptorStack);
199204
return null;
200205
}
201206
interceptorStack.add(executorInterceptor);
@@ -204,13 +209,13 @@ private Message<?> applyBeforeHandle(Message<?> message, Deque<ExecutorChannelIn
204209
return theMessage;
205210
}
206211

207-
private void triggerAfterMessageHandled(@Nullable Message<?> message, @Nullable Exception ex,
212+
private void triggerAfterMessageHandled(Message<?> message, @Nullable Exception ex,
208213
Deque<ExecutorChannelInterceptor> interceptorStack) {
209214
Iterator<ExecutorChannelInterceptor> iterator = interceptorStack.descendingIterator();
210215
while (iterator.hasNext()) {
211216
ExecutorChannelInterceptor interceptor = iterator.next();
212217
try {
213-
interceptor.afterMessageHandled(message, AbstractExecutorChannel.this, //NOSONAR
218+
interceptor.afterMessageHandled(message, AbstractExecutorChannel.this,
214219
this.delegate.getMessageHandler(), ex);
215220
}
216221
catch (Throwable ex2) { //NOSONAR

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.Deque;
2525
import java.util.Iterator;
2626
import java.util.List;
27+
import java.util.Objects;
2728
import java.util.Set;
2829
import java.util.concurrent.ConcurrentHashMap;
2930
import java.util.concurrent.CopyOnWriteArrayList;
@@ -95,28 +96,27 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport
9596

9697
private ObservationRegistry observationRegistry = ObservationRegistry.NOOP;
9798

98-
@Nullable
99-
private MessageSenderObservationConvention observationConvention;
99+
private @Nullable MessageSenderObservationConvention observationConvention;
100100

101101
private boolean shouldTrack = false;
102102

103103
private Class<?>[] datatypes = new Class<?>[0];
104104

105-
private MessageConverter messageConverter;
105+
private @Nullable MessageConverter messageConverter;
106106

107107
private boolean loggingEnabled = true;
108108

109-
private MetricsCaptor metricsCaptor;
109+
private @Nullable MetricsCaptor metricsCaptor;
110110

111-
private TimerFacade successTimer;
111+
private @Nullable TimerFacade successTimer;
112112

113-
private TimerFacade failureTimer;
113+
private @Nullable TimerFacade failureTimer;
114114

115-
private volatile String fullChannelName;
115+
private volatile @Nullable String fullChannelName;
116116

117117
private volatile boolean applicationRunning;
118118

119-
private volatile Lifecycle applicationRunningController;
119+
private volatile @Nullable Lifecycle applicationRunningController;
120120

121121
@Override
122122
public String getComponentType() {
@@ -235,9 +235,8 @@ public boolean removeInterceptor(ChannelInterceptor interceptor) {
235235
}
236236

237237
@Override
238-
@Nullable
239238
public ChannelInterceptor removeInterceptor(int index) {
240-
return this.interceptors.remove(index);
239+
return Objects.requireNonNull(this.interceptors.remove(index));
241240
}
242241

243242
/**
@@ -394,14 +393,15 @@ private boolean sendWithObservation(Message<?> message, long timeout) {
394393
messageToSendInternal =
395394
new ErrorMessage(errorMessage.getPayload(),
396395
messageToSend.getHeaders(),
397-
errorMessage.getOriginalMessage());
396+
Objects.requireNonNull(errorMessage.getOriginalMessage()));
398397
}
399398
return sendInternal(messageToSendInternal, timeout);
400399
});
401400
return Boolean.TRUE.equals(observe);
402401
}
403402

404403
private boolean sendWithMetrics(Message<?> message, long timeout) {
404+
Assert.state(this.metricsCaptor != null, "The metricsCaptor must not be null");
405405
SampleFacade sample = this.metricsCaptor.start();
406406
try {
407407
boolean sent = sendInternal(message, timeout);
@@ -469,6 +469,7 @@ private TimerFacade sendTimer(boolean sent) {
469469
}
470470

471471
private TimerFacade buildSendTimer(boolean success, String exception) {
472+
Assert.state(this.metricsCaptor != null, "The metricsCaptor must not be null");
472473
TimerFacade timer = this.metricsCaptor.timerBuilder(SEND_TIMER_NAME)
473474
.tag("type", "channel")
474475
.tag("name", getComponentName() == null ? "unknown" : getComponentName())

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public abstract class AbstractPollableChannel extends AbstractMessageChannel
4545

4646
private int executorInterceptorsSize;
4747

48-
private CounterFacade receiveCounter;
48+
private @Nullable CounterFacade receiveCounter;
4949

5050
@Override
5151
public IntegrationPatternType getIntegrationPatternType() {
@@ -186,7 +186,6 @@ public boolean removeInterceptor(ChannelInterceptor interceptor) {
186186
}
187187

188188
@Override
189-
@Nullable
190189
public ChannelInterceptor removeInterceptor(int index) {
191190
ChannelInterceptor interceptor = super.removeInterceptor(index);
192191
if (interceptor instanceof ExecutorChannelInterceptor) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class ChannelPurger {
4848

4949
private final QueueChannel[] channels;
5050

51-
private final MessageSelector selector;
51+
private final @Nullable MessageSelector selector;
5252

5353
public ChannelPurger(QueueChannel... channels) {
5454
this(null, channels);

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public class DefaultHeaderChannelRegistry extends IntegrationObjectSupport
6767

6868
private long reaperDelay;
6969

70-
private volatile ScheduledFuture<?> reaperScheduledFuture;
70+
private volatile @Nullable ScheduledFuture<?> reaperScheduledFuture;
7171

7272
private volatile boolean running;
7373

@@ -147,8 +147,9 @@ public void stop() {
147147
this.lock.lock();
148148
try {
149149
this.running = false;
150-
if (this.reaperScheduledFuture != null) {
151-
this.reaperScheduledFuture.cancel(true);
150+
ScheduledFuture<?> reaperScheduledFutureToCancel = this.reaperScheduledFuture;
151+
if (reaperScheduledFutureToCancel != null) {
152+
reaperScheduledFutureToCancel.cancel(true);
152153
this.reaperScheduledFuture = null;
153154
}
154155
this.explicitlyStopped = true;
@@ -221,8 +222,9 @@ public MessageChannel channelNameToChannel(@Nullable String name) {
221222
public void runReaper() {
222223
this.lock.lock();
223224
try {
224-
if (this.reaperScheduledFuture != null) {
225-
this.reaperScheduledFuture.cancel(true);
225+
ScheduledFuture<?> reaperScheduledFutureToCancel = this.reaperScheduledFuture;
226+
if (reaperScheduledFutureToCancel != null) {
227+
reaperScheduledFutureToCancel.cancel(true);
226228
this.reaperScheduledFuture = null;
227229
}
228230

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class DirectChannel extends AbstractSubscribableChannel {
3939

4040
private final UnicastingDispatcher dispatcher = new UnicastingDispatcher();
4141

42-
private volatile Integer maxSubscribers;
42+
private volatile @Nullable Integer maxSubscribers;
4343

4444
/**
4545
* Create a channel with default {@link RoundRobinLoadBalancingStrategy}.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
*/
5050
public class ExecutorChannel extends AbstractExecutorChannel {
5151

52-
private final LoadBalancingStrategy loadBalancingStrategy;
52+
private final @Nullable LoadBalancingStrategy loadBalancingStrategy;
5353

5454
private Predicate<Exception> failoverStrategy = (exception) -> true;
5555

0 commit comments

Comments
 (0)