Skip to content

Commit a61b9b8

Browse files
committed
Fix ErrorMessageExceptionTypeRouter for new Nullability
* Fix `KotlinIntegrationFlowDefinition` for new `RouterSpec` expectations **Auto-cherry-pick to `7.0.x`**
1 parent e4348f5 commit a61b9b8

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,9 @@ 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-
addChannelKeyToCollection(channels, message, channelKey);
372+
if (channelKey != null) {
373+
addChannelKeyToCollection(channels, message, channelKey);
374+
}
373375
}
374376
}
375377

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

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

26+
import org.jspecify.annotations.Nullable;
27+
2628
import org.springframework.jmx.export.annotation.ManagedAttribute;
2729
import org.springframework.jmx.export.annotation.ManagedOperation;
2830
import org.springframework.messaging.Message;
@@ -69,7 +71,6 @@ private void populateClassNameMapping(Set<String> classNames) {
6971

7072
private Class<?> resolveClassFromName(String className) {
7173
try {
72-
Assert.state(getApplicationContext() != null, "An ApplicationContext is required");
7374
return ClassUtils.forName(className, getApplicationContext().getClassLoader());
7475
}
7576
catch (ClassNotFoundException e) {
@@ -112,7 +113,7 @@ protected void onInit() {
112113
}
113114

114115
@Override
115-
protected List<Object> getChannelKeys(Message<?> message) {
116+
protected @Nullable List<Object> getChannelKeys(Message<?> message) {
116117
String mostSpecificCause = null;
117118
Object payload = message.getPayload();
118119
if (payload instanceof Throwable cause) {
@@ -127,7 +128,7 @@ protected List<Object> getChannelKeys(Message<?> message) {
127128
cause = cause.getCause();
128129
}
129130
}
130-
return Collections.singletonList(mostSpecificCause);
131+
return mostSpecificCause == null ? null : Collections.singletonList(mostSpecificCause);
131132
}
132133

133134
}

spring-integration-core/src/main/kotlin/org/springframework/integration/dsl/KotlinIntegrationFlowDefinition.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: Integ
724724
*/
725725
fun route(
726726
beanName: String, method: String?,
727-
routerConfigurer: KotlinRouterSpec<Any?, MethodInvokingRouter>.() -> Unit
727+
routerConfigurer: KotlinRouterSpec<Any, MethodInvokingRouter>.() -> Unit
728728
) {
729729

730730
this.delegate.route(beanName, method) { routerConfigurer(KotlinRouterSpec(it)) }
@@ -744,7 +744,7 @@ class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: Integ
744744
*/
745745
fun route(
746746
service: Any, methodName: String?,
747-
routerConfigurer: KotlinRouterSpec<Any?, MethodInvokingRouter>.() -> Unit
747+
routerConfigurer: KotlinRouterSpec<Any, MethodInvokingRouter>.() -> Unit
748748
) {
749749

750750
this.delegate.route(service, methodName) { routerConfigurer(KotlinRouterSpec(it)) }
@@ -754,9 +754,9 @@ class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: Integ
754754
* Populate the [ExpressionEvaluatingRouter] for provided SpEL expression
755755
* with provided options from [KotlinRouterSpec].
756756
*/
757-
fun <T : Any?> route(
757+
fun route(
758758
expression: String,
759-
routerConfigurer: KotlinRouterSpec<T, ExpressionEvaluatingRouter>.() -> Unit = {}
759+
routerConfigurer: KotlinRouterSpec<Any, ExpressionEvaluatingRouter>.() -> Unit = {}
760760
) {
761761

762762
this.delegate.route(expression) { routerConfigurer(KotlinRouterSpec(it)) }
@@ -768,7 +768,7 @@ class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: Integ
768768
*/
769769
fun route(
770770
messageProcessorSpec: MessageProcessorSpec<*>,
771-
routerConfigurer: KotlinRouterSpec<Any?, MethodInvokingRouter>.() -> Unit = {}
771+
routerConfigurer: KotlinRouterSpec<Any, MethodInvokingRouter>.() -> Unit = {}
772772
) {
773773

774774
this.delegate.route(messageProcessorSpec) { routerConfigurer(KotlinRouterSpec(it)) }

0 commit comments

Comments
 (0)