Skip to content

Commit 0503284

Browse files
authored
GH-10083: Apply Nullability to core dispatcher package
Related to: #10083 * Due to the high use of the `dispatch` method it is better to suppress the `NullAway` error, than take the performance hit of using `requiresNonNull` * Add comment to `PartitionedDispatcher.dispatch` stating why a `@SuppressWarning` is needed. * Correct comment PartitionedDispatcher.dispatch to state that partitionsMap never returns null. `PartititonDispatcher.partition` will always return at least 1 partition.
1 parent 5b63021 commit 0503284

File tree

6 files changed

+20
-9
lines changed

6 files changed

+20
-9
lines changed

spring-integration-core/src/main/java/org/springframework/integration/dispatcher/AbstractDispatcher.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import org.apache.commons.logging.Log;
2424
import org.apache.commons.logging.LogFactory;
25+
import org.jspecify.annotations.Nullable;
2526

2627
import org.springframework.integration.support.utils.IntegrationUtils;
2728
import org.springframework.messaging.Message;
@@ -53,7 +54,7 @@ public abstract class AbstractDispatcher implements MessageDispatcher {
5354

5455
private volatile int maxSubscribers = Integer.MAX_VALUE;
5556

56-
private volatile MessageHandler theOneHandler;
57+
private volatile @Nullable MessageHandler theOneHandler;
5758

5859
private final Lock lock = new ReentrantLock();
5960

spring-integration-core/src/main/java/org/springframework/integration/dispatcher/AggregateMessageDeliveryException.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.util.ArrayList;
2020
import java.util.List;
2121

22+
import org.jspecify.annotations.Nullable;
23+
2224
import org.springframework.messaging.Message;
2325
import org.springframework.messaging.MessageDeliveryException;
2426
import org.springframework.util.StringUtils;
@@ -30,6 +32,7 @@
3032
* @author Mark Fisher
3133
* @author Artem Bilan
3234
* @author Gary Russell
35+
* @author Glenn Renfro
3336
*
3437
* @since 1.0.3
3538
*/
@@ -69,7 +72,7 @@ public String getMessage() {
6972
return message.toString();
7073
}
7174

72-
private String appendPeriodIfNecessary(String baseMessage) {
75+
private String appendPeriodIfNecessary(@Nullable String baseMessage) {
7376
if (!StringUtils.hasText(baseMessage)) {
7477
return "";
7578
}

spring-integration-core/src/main/java/org/springframework/integration/dispatcher/BroadcastingDispatcher.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.util.UUID;
2121
import java.util.concurrent.Executor;
2222

23+
import org.jspecify.annotations.Nullable;
24+
2325
import org.springframework.beans.BeansException;
2426
import org.springframework.beans.factory.BeanFactory;
2527
import org.springframework.beans.factory.BeanFactoryAware;
@@ -56,12 +58,13 @@
5658
* @author Gary Russell
5759
* @author Oleg Zhurakousky
5860
* @author Artem Bilan
61+
* @author Glenn Renfro
5962
*/
6063
public class BroadcastingDispatcher extends AbstractDispatcher implements BeanFactoryAware {
6164

6265
private final boolean requireSubscribers;
6366

64-
private final Executor executor;
67+
private final @Nullable Executor executor;
6568

6669
private boolean ignoreFailures;
6770

@@ -71,6 +74,7 @@ public class BroadcastingDispatcher extends AbstractDispatcher implements BeanFa
7174

7275
private MessageHandlingTaskDecorator messageHandlingTaskDecorator = task -> task;
7376

77+
@SuppressWarnings("NullAway.Init")
7478
private BeanFactory beanFactory;
7579

7680
private volatile MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory();
@@ -89,7 +93,7 @@ public BroadcastingDispatcher(boolean requireSubscribers) {
8993
this(null, requireSubscribers);
9094
}
9195

92-
public BroadcastingDispatcher(Executor executor, boolean requireSubscribers) {
96+
public BroadcastingDispatcher(@Nullable Executor executor, boolean requireSubscribers) {
9397
this.requireSubscribers = requireSubscribers;
9498
this.executor = executor;
9599
}

spring-integration-core/src/main/java/org/springframework/integration/dispatcher/PartitionedDispatcher.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
*
5555
* @author Artem Bilan
5656
* @author Christian Tzolov
57+
* @author Glenn Renfro
5758
*
5859
* @since 6.1
5960
*/
@@ -71,10 +72,9 @@ public class PartitionedDispatcher extends AbstractDispatcher {
7172

7273
private Predicate<Exception> failoverStrategy = (exception) -> true;
7374

74-
@Nullable
75-
private LoadBalancingStrategy loadBalancingStrategy;
75+
private @Nullable LoadBalancingStrategy loadBalancingStrategy;
7676

77-
private ErrorHandler errorHandler;
77+
private @Nullable ErrorHandler errorHandler;
7878

7979
private MessageHandlingTaskDecorator messageHandlingTaskDecorator = task -> task;
8080

@@ -164,6 +164,7 @@ public void shutdown() {
164164
}
165165

166166
@Override
167+
@SuppressWarnings("NullAway") // The partitions map never returns null according to partition hash
167168
public boolean dispatch(Message<?> message) {
168169
populatedPartitions();
169170
int partition = Math.abs(this.partitionKeyFunction.apply(message).hashCode()) % this.partitionCount;

spring-integration-core/src/main/java/org/springframework/integration/dispatcher/UnicastingDispatcher.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,19 @@
5151
* @author Gary Russell
5252
* @author Oleg Zhurakousky
5353
* @author Artem Bilan
54+
* @author Glenn Renfro
5455
*
5556
* @since 1.0.2
5657
*/
5758
public class UnicastingDispatcher extends AbstractDispatcher {
5859

5960
private final MessageHandler dispatchHandler = this::doDispatch;
6061

61-
private final Executor executor;
62+
private final @Nullable Executor executor;
6263

6364
private Predicate<Exception> failoverStrategy = (exception) -> true;
6465

65-
private LoadBalancingStrategy loadBalancingStrategy;
66+
private @Nullable LoadBalancingStrategy loadBalancingStrategy;
6667

6768
private MessageHandlingTaskDecorator messageHandlingTaskDecorator = task -> task;
6869

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/**
22
* Provides classes related to dispatching messages.
33
*/
4+
@org.jspecify.annotations.NullMarked
45
package org.springframework.integration.dispatcher;

0 commit comments

Comments
 (0)