Skip to content

Commit 700fede

Browse files
committed
Consistent not-null assertions for configured interceptors
Closes spring-projectsgh-25221
1 parent 31cda09 commit 700fede

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

spring-messaging/src/main/java/org/springframework/messaging/support/AbstractMessageChannel.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -75,11 +75,13 @@ public void setInterceptors(List<ChannelInterceptor> interceptors) {
7575

7676
@Override
7777
public void addInterceptor(ChannelInterceptor interceptor) {
78+
Assert.notNull(interceptor, "ChannelInterceptor must not be null");
7879
this.interceptors.add(interceptor);
7980
}
8081

8182
@Override
8283
public void addInterceptor(int index, ChannelInterceptor interceptor) {
84+
Assert.notNull(interceptor, "ChannelInterceptor must not be null");
8385
this.interceptors.add(index, interceptor);
8486
}
8587

@@ -107,29 +109,30 @@ public final boolean send(Message<?> message) {
107109
@Override
108110
public final boolean send(Message<?> message, long timeout) {
109111
Assert.notNull(message, "Message must not be null");
112+
Message<?> messageToUse = message;
110113
ChannelInterceptorChain chain = new ChannelInterceptorChain();
111114
boolean sent = false;
112115
try {
113-
message = chain.applyPreSend(message, this);
114-
if (message == null) {
116+
messageToUse = chain.applyPreSend(messageToUse, this);
117+
if (messageToUse == null) {
115118
return false;
116119
}
117-
sent = sendInternal(message, timeout);
118-
chain.applyPostSend(message, this, sent);
119-
chain.triggerAfterSendCompletion(message, this, sent, null);
120+
sent = sendInternal(messageToUse, timeout);
121+
chain.applyPostSend(messageToUse, this, sent);
122+
chain.triggerAfterSendCompletion(messageToUse, this, sent, null);
120123
return sent;
121124
}
122125
catch (Exception ex) {
123-
chain.triggerAfterSendCompletion(message, this, sent, ex);
126+
chain.triggerAfterSendCompletion(messageToUse, this, sent, ex);
124127
if (ex instanceof MessagingException) {
125128
throw (MessagingException) ex;
126129
}
127-
throw new MessageDeliveryException(message,"Failed to send message to " + this, ex);
130+
throw new MessageDeliveryException(messageToUse,"Failed to send message to " + this, ex);
128131
}
129132
catch (Throwable err) {
130133
MessageDeliveryException ex2 =
131-
new MessageDeliveryException(message, "Failed to send message to " + this, err);
132-
chain.triggerAfterSendCompletion(message, this, sent, ex2);
134+
new MessageDeliveryException(messageToUse, "Failed to send message to " + this, err);
135+
chain.triggerAfterSendCompletion(messageToUse, this, sent, ex2);
133136
throw ex2;
134137
}
135138
}
@@ -200,13 +203,14 @@ public boolean applyPreReceive(MessageChannel channel) {
200203
}
201204

202205
public Message<?> applyPostReceive(Message<?> message, MessageChannel channel) {
206+
Message<?> messageToUse = message;
203207
for (ChannelInterceptor interceptor : interceptors) {
204-
message = interceptor.postReceive(message, channel);
205-
if (message == null) {
208+
messageToUse = interceptor.postReceive(messageToUse, channel);
209+
if (messageToUse == null) {
206210
return null;
207211
}
208212
}
209-
return message;
213+
return messageToUse;
210214
}
211215

212216
public void triggerAfterReceiveCompletion(Message<?> message, MessageChannel channel, Exception ex) {

0 commit comments

Comments
 (0)