Skip to content

Commit 9596b70

Browse files
committed
Consistent nullability and exception declarations
Closes gh-35159
1 parent 292ea17 commit 9596b70

9 files changed

+113
-84
lines changed

spring-jms/src/main/java/org/springframework/jms/core/JmsMessageOperations.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@
3030

3131
/**
3232
* A specialization of {@link MessageSendingOperations}, {@link MessageReceivingOperations}
33-
* and {@link MessageRequestReplyOperations} for JMS related operations that allow to specify
34-
* a destination name rather than the actual {@link jakarta.jms.Destination}.
33+
* and {@link MessageRequestReplyOperations} for JMS related operations that allow to
34+
* specify a destination name rather than the actual {@link jakarta.jms.Destination}.
35+
*
36+
* <p>Note: Operations in this interface throw {@link MessagingException} instead of
37+
* the JMS-specific {@link org.springframework.jms.JmsException}, aligning with the
38+
* {@code spring-messaging} module and its other client operation handles.
3539
*
3640
* @author Stephane Nicoll
3741
* @since 4.1
@@ -68,30 +72,30 @@ public interface JmsMessageOperations extends MessageSendingOperations<Destinati
6872
* @param payload the Object to use as payload
6973
* @param headers the headers for the message to send
7074
*/
71-
void convertAndSend(String destinationName, Object payload, Map<String, Object> headers)
75+
void convertAndSend(String destinationName, Object payload, @Nullable Map<String, Object> headers)
7276
throws MessagingException;
7377

7478
/**
7579
* Convert the given Object to serialized form, possibly using a
7680
* {@link org.springframework.messaging.converter.MessageConverter},
77-
* wrap it as a message, apply the given post processor, and send
81+
* wrap it as a message, apply the given post-processor, and send
7882
* the resulting message to the given destination.
7983
* @param destinationName the name of the target destination
8084
* @param payload the Object to use as payload
81-
* @param postProcessor the post processor to apply to the message
85+
* @param postProcessor the post-processor to apply to the message
8286
*/
83-
void convertAndSend(String destinationName, Object payload, MessagePostProcessor postProcessor)
87+
void convertAndSend(String destinationName, Object payload, @Nullable MessagePostProcessor postProcessor)
8488
throws MessagingException;
8589

8690
/**
8791
* Convert the given Object to serialized form, possibly using a
8892
* {@link org.springframework.messaging.converter.MessageConverter},
89-
* wrap it as a message with the given headers, apply the given post processor,
93+
* wrap it as a message with the given headers, apply the given post-processor,
9094
* and send the resulting message to the given destination.
9195
* @param destinationName the name of the target destination
9296
* @param payload the Object to use as payload
9397
* @param headers the headers for the message to send
94-
* @param postProcessor the post processor to apply to the message
98+
* @param postProcessor the post-processor to apply to the message
9599
*/
96100
void convertAndSend(String destinationName, Object payload, @Nullable Map<String, Object> headers,
97101
@Nullable MessagePostProcessor postProcessor) throws MessagingException;
@@ -159,13 +163,13 @@ <T> T convertSendAndReceive(String destinationName, Object request, @Nullable Ma
159163
/**
160164
* Convert the given request Object to serialized form, possibly using a
161165
* {@link org.springframework.messaging.converter.MessageConverter},
162-
* apply the given post processor and send the resulting {@link Message} to the
166+
* apply the given post-processor and send the resulting {@link Message} to the
163167
* given destination, receive the reply and convert its body of the given
164168
* target class.
165169
* @param destinationName the name of the target destination
166170
* @param request payload for the request message to send
167171
* @param targetClass the target type to convert the payload of the reply to
168-
* @param requestPostProcessor post process to apply to the request message
172+
* @param requestPostProcessor post-process to apply to the request message
169173
* @return the payload of the reply message, possibly {@code null} if the message
170174
* could not be received, for example due to a timeout
171175
*/
@@ -176,13 +180,13 @@ <T> T convertSendAndReceive(String destinationName, Object request, Class<T> tar
176180
/**
177181
* Convert the given request Object to serialized form, possibly using a
178182
* {@link org.springframework.messaging.converter.MessageConverter},
179-
* wrap it as a message with the given headers, apply the given post processor
183+
* wrap it as a message with the given headers, apply the given post-processor
180184
* and send the resulting {@link Message} to the specified destination, receive
181185
* the reply and convert its body of the given target class.
182186
* @param destinationName the name of the target destination
183187
* @param request payload for the request message to send
184188
* @param targetClass the target type to convert the payload of the reply to
185-
* @param requestPostProcessor post process to apply to the request message
189+
* @param requestPostProcessor post-process to apply to the request message
186190
* @return the payload of the reply message, possibly {@code null} if the message
187191
* could not be received, for example due to a timeout
188192
*/

spring-messaging/src/main/java/org/springframework/messaging/core/AbstractDestinationResolvingMessagingTemplate.java

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import org.springframework.lang.Nullable;
2222
import org.springframework.messaging.Message;
23+
import org.springframework.messaging.MessagingException;
2324
import org.springframework.util.Assert;
2425

2526
/**
@@ -65,74 +66,82 @@ public DestinationResolver<D> getDestinationResolver() {
6566
return this.destinationResolver;
6667
}
6768

69+
protected final D resolveDestination(String destinationName) throws DestinationResolutionException {
70+
Assert.state(this.destinationResolver != null,
71+
"DestinationResolver is required to resolve destination names");
72+
return this.destinationResolver.resolveDestination(destinationName);
73+
}
74+
6875

6976
@Override
70-
public void send(String destinationName, Message<?> message) {
77+
public void send(String destinationName, Message<?> message) throws MessagingException {
7178
D destination = resolveDestination(destinationName);
7279
doSend(destination, message);
7380
}
7481

75-
protected final D resolveDestination(String destinationName) {
76-
77-
Assert.state(this.destinationResolver != null, "DestinationResolver is required to resolve destination names");
78-
return this.destinationResolver.resolveDestination(destinationName);
79-
}
80-
8182
@Override
82-
public <T> void convertAndSend(String destinationName, T payload) {
83+
public <T> void convertAndSend(String destinationName, T payload) throws MessagingException {
8384
convertAndSend(destinationName, payload, null, null);
8485
}
8586

8687
@Override
87-
public <T> void convertAndSend(String destinationName, T payload, @Nullable Map<String, Object> headers) {
88+
public <T> void convertAndSend(String destinationName, T payload, @Nullable Map<String, Object> headers)
89+
throws MessagingException {
90+
8891
convertAndSend(destinationName, payload, headers, null);
8992
}
9093

9194
@Override
92-
public <T> void convertAndSend(String destinationName, T payload, @Nullable MessagePostProcessor postProcessor) {
95+
public <T> void convertAndSend(String destinationName, T payload, @Nullable MessagePostProcessor postProcessor)
96+
throws MessagingException {
97+
9398
convertAndSend(destinationName, payload, null, postProcessor);
9499
}
95100

96101
@Override
97-
public <T> void convertAndSend(String destinationName, T payload,
98-
@Nullable Map<String, Object> headers, @Nullable MessagePostProcessor postProcessor) {
102+
public <T> void convertAndSend(String destinationName, T payload, @Nullable Map<String, Object> headers,
103+
@Nullable MessagePostProcessor postProcessor) throws MessagingException {
99104

100105
D destination = resolveDestination(destinationName);
101106
super.convertAndSend(destination, payload, headers, postProcessor);
102107
}
103108

104109
@Override
105110
@Nullable
106-
public Message<?> receive(String destinationName) {
111+
public Message<?> receive(String destinationName) throws MessagingException {
107112
D destination = resolveDestination(destinationName);
108113
return super.receive(destination);
109114
}
110115

111116
@Override
112117
@Nullable
113-
public <T> T receiveAndConvert(String destinationName, Class<T> targetClass) {
118+
public <T> T receiveAndConvert(String destinationName, Class<T> targetClass) throws MessagingException {
114119
D destination = resolveDestination(destinationName);
115120
return super.receiveAndConvert(destination, targetClass);
116121
}
117122

118123
@Override
119124
@Nullable
120-
public Message<?> sendAndReceive(String destinationName, Message<?> requestMessage) {
125+
public Message<?> sendAndReceive(String destinationName, Message<?> requestMessage)
126+
throws MessagingException {
127+
121128
D destination = resolveDestination(destinationName);
122129
return super.sendAndReceive(destination, requestMessage);
123130
}
124131

125132
@Override
126133
@Nullable
127-
public <T> T convertSendAndReceive(String destinationName, Object request, Class<T> targetClass) {
134+
public <T> T convertSendAndReceive(String destinationName, Object request, Class<T> targetClass)
135+
throws MessagingException {
136+
128137
D destination = resolveDestination(destinationName);
129138
return super.convertSendAndReceive(destination, request, targetClass);
130139
}
131140

132141
@Override
133142
@Nullable
134143
public <T> T convertSendAndReceive(String destinationName, Object request,
135-
@Nullable Map<String, Object> headers, Class<T> targetClass) {
144+
@Nullable Map<String, Object> headers, Class<T> targetClass) throws MessagingException {
136145

137146
D destination = resolveDestination(destinationName);
138147
return super.convertSendAndReceive(destination, request, headers, targetClass);
@@ -141,7 +150,7 @@ public <T> T convertSendAndReceive(String destinationName, Object request,
141150
@Override
142151
@Nullable
143152
public <T> T convertSendAndReceive(String destinationName, Object request, Class<T> targetClass,
144-
@Nullable MessagePostProcessor postProcessor) {
153+
@Nullable MessagePostProcessor postProcessor) throws MessagingException {
145154

146155
D destination = resolveDestination(destinationName);
147156
return super.convertSendAndReceive(destination, request, targetClass, postProcessor);
@@ -151,7 +160,7 @@ public <T> T convertSendAndReceive(String destinationName, Object request, Class
151160
@Nullable
152161
public <T> T convertSendAndReceive(String destinationName, Object request,
153162
@Nullable Map<String, Object> headers, Class<T> targetClass,
154-
@Nullable MessagePostProcessor postProcessor) {
163+
@Nullable MessagePostProcessor postProcessor) throws MessagingException {
155164

156165
D destination = resolveDestination(destinationName);
157166
return super.convertSendAndReceive(destination, request, headers, targetClass, postProcessor);

spring-messaging/src/main/java/org/springframework/messaging/core/AbstractMessageReceivingTemplate.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.springframework.lang.Nullable;
2020
import org.springframework.messaging.Message;
21+
import org.springframework.messaging.MessagingException;
2122
import org.springframework.messaging.converter.MessageConversionException;
2223
import org.springframework.messaging.converter.MessageConverter;
2324

@@ -36,35 +37,25 @@ public abstract class AbstractMessageReceivingTemplate<D> extends AbstractMessag
3637

3738
@Override
3839
@Nullable
39-
public Message<?> receive() {
40+
public Message<?> receive() throws MessagingException {
4041
return doReceive(getRequiredDefaultDestination());
4142
}
4243

4344
@Override
4445
@Nullable
45-
public Message<?> receive(D destination) {
46+
public Message<?> receive(D destination) throws MessagingException {
4647
return doReceive(destination);
4748
}
4849

49-
/**
50-
* Actually receive a message from the given destination.
51-
* @param destination the target destination
52-
* @return the received message, possibly {@code null} if the message could not
53-
* be received, for example due to a timeout
54-
*/
55-
@Nullable
56-
protected abstract Message<?> doReceive(D destination);
57-
58-
5950
@Override
6051
@Nullable
61-
public <T> T receiveAndConvert(Class<T> targetClass) {
52+
public <T> T receiveAndConvert(Class<T> targetClass) throws MessagingException {
6253
return receiveAndConvert(getRequiredDefaultDestination(), targetClass);
6354
}
6455

6556
@Override
6657
@Nullable
67-
public <T> T receiveAndConvert(D destination, Class<T> targetClass) {
58+
public <T> T receiveAndConvert(D destination, Class<T> targetClass) throws MessagingException {
6859
Message<?> message = doReceive(destination);
6960
if (message != null) {
7061
return doConvert(message, targetClass);
@@ -92,4 +83,13 @@ protected <T> T doConvert(Message<?> message, Class<T> targetClass) {
9283
return value;
9384
}
9485

86+
/**
87+
* Actually receive a message from the given destination.
88+
* @param destination the target destination
89+
* @return the received message, possibly {@code null} if the
90+
* message could not be received, for example due to a timeout
91+
*/
92+
@Nullable
93+
protected abstract Message<?> doReceive(D destination);
94+
9595
}

spring-messaging/src/main/java/org/springframework/messaging/core/AbstractMessageSendingTemplate.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,6 @@ public void send(D destination, Message<?> message) {
109109
doSend(destination, message);
110110
}
111111

112-
protected abstract void doSend(D destination, Message<?> message);
113-
114-
115112
@Override
116113
public void convertAndSend(Object payload) throws MessagingException {
117114
convertAndSend(payload, null);
@@ -151,13 +148,14 @@ public void convertAndSend(D destination, Object payload, @Nullable Map<String,
151148
send(destination, message);
152149
}
153150

151+
154152
/**
155153
* Convert the given Object to serialized form, possibly using a
156154
* {@link MessageConverter}, wrap it as a message with the given
157-
* headers and apply the given post processor.
155+
* headers and apply the given post-processor.
158156
* @param payload the Object to use as payload
159157
* @param headers the headers for the message to send
160-
* @param postProcessor the post processor to apply to the message
158+
* @param postProcessor the post-processor to apply to the message
161159
* @return the converted message
162160
*/
163161
protected Message<?> doConvert(Object payload, @Nullable Map<String, Object> headers,
@@ -199,4 +197,11 @@ protected Map<String, Object> processHeadersToSend(@Nullable Map<String, Object>
199197
return headers;
200198
}
201199

200+
/**
201+
* Actually send the given message to the given destination.
202+
* @param destination the target destination
203+
* @param message the message to send
204+
*/
205+
protected abstract void doSend(D destination, Message<?> message);
206+
202207
}

0 commit comments

Comments
 (0)