Skip to content

Commit e4348f5

Browse files
committed
Upgrade to io.spring.nullability:0.0.13
* Fix `AbstractMappingMessageRouter` hierarchy and `JdbcMessageStore` to satisfy Nullability **Auto-cherry-pick to `7.0.x`**
1 parent 4aa1ac7 commit e4348f5

File tree

9 files changed

+38
-27
lines changed

9 files changed

+38
-27
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,4 @@ antora = { id = "org.antora", version = "1.0.0" }
160160
io-spring-antora-generate-yml = { id = "io.spring.antora.generate-antora-yml", version = "0.0.1" }
161161
protobuf = { id = "com.google.protobuf", version = "0.9.6" }
162162
aggregate-javadoc = { id = "io.freefair.aggregate-javadoc", version = "9.2.0" }
163-
nullability = { id = "io.spring.nullability", version = "0.0.12" }
163+
nullability = { id = "io.spring.nullability", version = "0.0.13" }

spring-integration-core/src/main/java/org/springframework/integration/dsl/BaseIntegrationFlowDefinition.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,7 +1653,7 @@ public B route(String beanName, @Nullable String method) {
16531653
* @return the current {@link BaseIntegrationFlowDefinition}.
16541654
*/
16551655
public B route(String beanName, @Nullable String method,
1656-
@Nullable Consumer<RouterSpec<@Nullable Object, MethodInvokingRouter>> routerConfigurer) {
1656+
@Nullable Consumer<RouterSpec<Object, MethodInvokingRouter>> routerConfigurer) {
16571657

16581658
MethodInvokingRouter methodInvokingRouter =
16591659
new MethodInvokingRouter(new BeanNameMessageProcessor<>(beanName, method));
@@ -1693,7 +1693,7 @@ public B route(Object service, @Nullable String methodName) {
16931693
* @see MethodInvokingRouter
16941694
*/
16951695
public B route(Object service, @Nullable String methodName,
1696-
@Nullable Consumer<RouterSpec<@Nullable Object, MethodInvokingRouter>> routerConfigurer) {
1696+
@Nullable Consumer<RouterSpec<Object, MethodInvokingRouter>> routerConfigurer) {
16971697

16981698
MethodInvokingRouter router;
16991699
if (StringUtils.hasText(methodName)) {
@@ -1805,7 +1805,7 @@ public B route(String expression) {
18051805
* @return the current {@link BaseIntegrationFlowDefinition}.
18061806
*/
18071807
public B route(MessageProcessorSpec<?> messageProcessorSpec) {
1808-
return route(messageProcessorSpec, (Consumer<RouterSpec<@Nullable Object, MethodInvokingRouter>>) null);
1808+
return route(messageProcessorSpec, (Consumer<RouterSpec<Object, MethodInvokingRouter>>) null);
18091809
}
18101810

18111811
/**
@@ -1825,7 +1825,7 @@ public B route(MessageProcessorSpec<?> messageProcessorSpec) {
18251825
* @return the current {@link BaseIntegrationFlowDefinition}.
18261826
*/
18271827
public B route(MessageProcessorSpec<?> messageProcessorSpec,
1828-
@Nullable Consumer<RouterSpec<@Nullable Object, MethodInvokingRouter>> routerConfigurer) {
1828+
@Nullable Consumer<RouterSpec<Object, MethodInvokingRouter>> routerConfigurer) {
18291829

18301830
Assert.notNull(messageProcessorSpec, MESSAGE_PROCESSOR_SPEC_MUST_NOT_BE_NULL);
18311831
MessageProcessor<?> processor = messageProcessorSpec.getObject();

spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMappingMessageRouter.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ protected void onInit() {
264264

265265
@Override
266266
protected Collection<MessageChannel> determineTargetChannels(Message<?> message) {
267-
Collection<@Nullable Object> channelKeys = getChannelKeys(message);
267+
Collection<Object> channelKeys = getChannelKeys(message);
268268
if (channelKeys != null) {
269269
Collection<MessageChannel> channels = new ArrayList<>(channelKeys.size());
270270
addToCollection(channels, channelKeys, message);
@@ -282,7 +282,7 @@ protected Collection<MessageChannel> determineTargetChannels(Message<?> message)
282282
* @param message The message.
283283
* @return The channel keys.
284284
*/
285-
protected abstract @Nullable List<@Nullable Object> getChannelKeys(Message<?> message);
285+
protected abstract @Nullable List<Object> getChannelKeys(Message<?> message);
286286

287287
/**
288288
* Convenience method allowing conversion of a list
@@ -369,9 +369,7 @@ private void addChannel(Collection<MessageChannel> channels, Message<?> message,
369369

370370
private void addToCollection(Collection<MessageChannel> channels, Collection<?> channelKeys, Message<?> message) {
371371
for (Object channelKey : channelKeys) {
372-
if (channelKey != null) {
373-
addChannelKeyToCollection(channels, message, channelKey);
374-
}
372+
addChannelKeyToCollection(channels, message, channelKey);
375373
}
376374
}
377375

spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMessageProcessingRouter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public final void onInit() {
5757
((AbstractMessageProcessor<?>) this.messageProcessor).setConversionService(conversionService);
5858
}
5959
}
60-
if (this.messageProcessor instanceof BeanFactoryAware beanFactoryAware && this.getBeanFactory() != null) {
60+
if (this.messageProcessor instanceof BeanFactoryAware beanFactoryAware && getBeanFactory() != null) {
6161
beanFactoryAware.setBeanFactory(this.getBeanFactory());
6262
}
6363
}
@@ -82,9 +82,9 @@ public boolean isRunning() {
8282
}
8383

8484
@Override
85-
protected List<@Nullable Object> getChannelKeys(Message<?> message) {
85+
protected @Nullable List<Object> getChannelKeys(Message<?> message) {
8686
Object result = this.messageProcessor.processMessage(message);
87-
return Collections.singletonList(result);
87+
return result == null ? null : Collections.singletonList(result);
8888
}
8989

9090
}

spring-integration-core/src/main/java/org/springframework/integration/router/ErrorMessageExceptionTypeRouter.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
import java.util.Properties;
2424
import java.util.Set;
2525

26-
import org.jspecify.annotations.Nullable;
27-
2826
import org.springframework.jmx.export.annotation.ManagedAttribute;
2927
import org.springframework.jmx.export.annotation.ManagedOperation;
3028
import org.springframework.messaging.Message;
@@ -114,7 +112,7 @@ protected void onInit() {
114112
}
115113

116114
@Override
117-
protected List<@Nullable Object> getChannelKeys(Message<?> message) {
115+
protected List<Object> getChannelKeys(Message<?> message) {
118116
String mostSpecificCause = null;
119117
Object payload = message.getPayload();
120118
if (payload instanceof Throwable cause) {

spring-integration-core/src/main/java/org/springframework/integration/router/HeaderValueRouter.java

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

22-
import org.jspecify.annotations.Nullable;
23-
2422
import org.springframework.messaging.Message;
2523
import org.springframework.util.Assert;
2624
import org.springframework.util.StringUtils;
@@ -30,14 +28,15 @@
3028
*
3129
* @author Oleg Zhurakousky
3230
* @author Mark Fisher
31+
*
3332
* @since 1.0.3
3433
*/
3534
public class HeaderValueRouter extends AbstractMappingMessageRouter {
3635

3736
private final String headerName;
3837

3938
/**
40-
* Create a router that uses the provided header name to lookup a channel.
39+
* Create a router that uses the provided header name to look up a channel.
4140
*
4241
* @param headerName The header name.
4342
*/
@@ -47,7 +46,7 @@ public HeaderValueRouter(String headerName) {
4746
}
4847

4948
@Override
50-
protected List<@Nullable Object> getChannelKeys(Message<?> message) {
49+
protected List<Object> getChannelKeys(Message<?> message) {
5150
Object value = message.getHeaders().get(this.headerName);
5251
if (value instanceof String && ((String) value).indexOf(',') != -1) {
5352
value = StringUtils.tokenizeToStringArray((String) value, ",");

spring-integration-core/src/main/java/org/springframework/integration/router/PayloadTypeRouter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class PayloadTypeRouter extends AbstractMappingMessageRouter {
4949
* preferring direct interface to indirect subclass
5050
*/
5151
@Override
52-
protected @Nullable List<@Nullable Object> getChannelKeys(Message<?> message) {
52+
protected @Nullable List<Object> getChannelKeys(Message<?> message) {
5353
if (CollectionUtils.isEmpty(getChannelMappings())) {
5454
return null;
5555
}
@@ -59,7 +59,7 @@ public class PayloadTypeRouter extends AbstractMappingMessageRouter {
5959
type = type.getComponentType();
6060
}
6161
String closestMatch = findClosestMatch(type, isArray);
62-
return (closestMatch != null) ? Collections.<@Nullable Object>singletonList(closestMatch) : null;
62+
return (closestMatch != null) ? Collections.singletonList(closestMatch) : null;
6363
}
6464

6565
private @Nullable String findClosestMatch(Class<?> type, boolean isArray) { // NOSONAR

spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/JdbcMessageStore.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.integration.jdbc.store;
1818

1919
import java.sql.Timestamp;
20+
import java.util.ArrayList;
2021
import java.util.Arrays;
2122
import java.util.Collection;
2223
import java.util.Iterator;
@@ -713,9 +714,15 @@ public Stream<Message<?>> streamMessagesForGroup(Object groupId) {
713714

714715
@Override
715716
public Iterator<MessageGroup> iterator() {
716-
List<String> groupIds =
717+
List<@Nullable String> groupIds =
717718
this.jdbcTemplate.query(getQuery(Query.LIST_GROUP_KEYS), new SingleColumnRowMapper<>(), this.region);
718-
return new FunctionIterator<>(groupIds, this::getMessageGroup);
719+
List<String> groupIdsToMap = new ArrayList<>(groupIds.size());
720+
for (String groupId : groupIds) {
721+
if (groupId != null) {
722+
groupIdsToMap.add(groupId);
723+
}
724+
}
725+
return new FunctionIterator<>(groupIdsToMap, this::getMessageGroup);
719726
}
720727

721728
/**

spring-integration-xml/src/main/java/org/springframework/integration/xml/router/XPathRouter.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.integration.xml.router;
1818

19+
import java.util.ArrayList;
1920
import java.util.Collections;
2021
import java.util.HashMap;
2122
import java.util.List;
@@ -114,13 +115,21 @@ public String getComponentType() {
114115
}
115116

116117
@Override
117-
protected List<@Nullable Object> getChannelKeys(Message<?> message) {
118+
protected @Nullable List<Object> getChannelKeys(Message<?> message) {
118119
Node node = this.converter.convertToNode(message.getPayload());
119120
if (this.evaluateAsString) {
120-
return Collections.<@Nullable Object>singletonList(this.xPathExpression.evaluateAsString(node));
121+
String channelKey = this.xPathExpression.evaluateAsString(node);
122+
return channelKey == null ? null : Collections.singletonList(channelKey);
121123
}
122124
else {
123-
return this.xPathExpression.evaluate(node, this.nodeMapper);
125+
List<@Nullable Object> resultList = this.xPathExpression.evaluate(node, this.nodeMapper);
126+
List<Object> channelKeys = new ArrayList<>(resultList.size());
127+
for (Object result : resultList) {
128+
if (result != null) {
129+
channelKeys.add(result);
130+
}
131+
}
132+
return channelKeys;
124133
}
125134
}
126135

0 commit comments

Comments
 (0)