Skip to content

Commit 4b10bc6

Browse files
committed
Fix Nullability according to SF changes
* Migrate from deprecated `org.springframework.context.expression.MapAccessor` to a new `org.springframework.expression.spel.support.MapAccessor`
1 parent 6e4c3d1 commit 4b10bc6

File tree

7 files changed

+32
-34
lines changed

7 files changed

+32
-34
lines changed

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/config/StatelessRetryOperationsInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public final class StatelessRetryOperationsInterceptor implements MethodIntercep
5454
@Override
5555
public @Nullable Object invoke(final MethodInvocation invocation) throws Throwable {
5656
try {
57-
return this.retryOperations.execute(invocation::proceed);
57+
return this.retryOperations.<@Nullable Object>execute(invocation::proceed);
5858
}
5959
catch (RetryException ex) {
6060
if (this.recoverer != null) {

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/core/ChannelCallback.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* @author Gary Russell
2828
*/
2929
@FunctionalInterface
30-
public interface ChannelCallback<T> {
30+
public interface ChannelCallback<T extends @Nullable Object> {
3131

3232
/**
3333
* Execute any number of operations against the supplied RabbitMQ
@@ -37,7 +37,6 @@ public interface ChannelCallback<T> {
3737
* @return The result.
3838
* @throws Exception Not sure what else Rabbit Throws
3939
*/
40-
@Nullable
4140
T doInRabbit(Channel channel) throws Exception; // NOSONAR user code might throw anything; cannot change
4241

4342
}

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/core/RabbitAdmin.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public RabbitTemplate getRabbitTemplate() {
234234
@Override
235235
public void declareExchange(final Exchange exchange) {
236236
try {
237-
this.rabbitTemplate.execute(channel -> {
237+
this.rabbitTemplate.<@Nullable Object>execute(channel -> {
238238
declareExchanges(channel, exchange);
239239
if (this.redeclareManualDeclarations) {
240240
this.manualDeclarables.add(exchange);
@@ -301,7 +301,7 @@ private void removeExchangeBindings(final String exchangeName) {
301301
@ManagedOperation(description = "Declare a queue on the broker (this operation is not available remotely)")
302302
public @Nullable String declareQueue(final Queue queue) {
303303
try {
304-
return this.rabbitTemplate.execute(channel -> {
304+
return this.rabbitTemplate.<@Nullable String>execute(channel -> {
305305
DeclareOk[] declared = declareQueues(channel, queue);
306306
String result = declared.length > 0 ? declared[0].getQueue() : null;
307307
if (this.redeclareManualDeclarations) {
@@ -358,7 +358,7 @@ public boolean deleteQueue(final String queueName) {
358358
@ManagedOperation(description =
359359
"Delete a queue from the broker if unused and empty (when corresponding arguments are true")
360360
public void deleteQueue(final String queueName, final boolean unused, final boolean empty) {
361-
this.rabbitTemplate.execute(channel -> {
361+
this.rabbitTemplate.<@Nullable Object>execute(channel -> {
362362
channel.queueDelete(queueName, unused, empty);
363363
removeQueueBindings(queueName);
364364
return null;
@@ -412,7 +412,7 @@ public int purgeQueue(final String queueName) {
412412
@ManagedOperation(description = "Declare a binding on the broker (this operation is not available remotely)")
413413
public void declareBinding(final Binding binding) {
414414
try {
415-
this.rabbitTemplate.execute(channel -> {
415+
this.rabbitTemplate.<@Nullable Object>execute(channel -> {
416416
declareBindings(channel, binding);
417417
if (this.redeclareManualDeclarations) {
418418
this.manualDeclarables.add(binding);
@@ -428,7 +428,7 @@ public void declareBinding(final Binding binding) {
428428
@Override
429429
@ManagedOperation(description = "Remove a binding from the broker (this operation is not available remotely)")
430430
public void removeBinding(final Binding binding) {
431-
this.rabbitTemplate.execute(channel -> {
431+
this.rabbitTemplate.<@Nullable Object>execute(channel -> {
432432
if (binding.isDestinationQueue()) {
433433
if (isRemovingImplicitQueueBinding(binding)) {
434434
return null;
@@ -469,7 +469,7 @@ public void removeBinding(final Binding binding) {
469469
@Override
470470
public @Nullable QueueInformation getQueueInfo(String queueName) {
471471
Assert.hasText(queueName, "'queueName' cannot be null or empty");
472-
return this.rabbitTemplate.execute(channel -> {
472+
return this.rabbitTemplate.<@Nullable QueueInformation>execute(channel -> {
473473
try {
474474
DeclareOk declareOk = channel.queueDeclarePassive(queueName);
475475
return new QueueInformation(declareOk.getQueue(), declareOk.getMessageCount(),
@@ -627,7 +627,7 @@ public void afterPropertiesSet() {
627627
* declared for every connection. If anyone has a problem with it: use auto-startup="false".
628628
*/
629629
if (this.retryTemplate != null) {
630-
this.retryTemplate.execute(() -> {
630+
this.retryTemplate.<@Nullable Object>execute(() -> {
631631
initialize();
632632
return null;
633633
});
@@ -712,7 +712,7 @@ private void redeclareBeanDeclarables() {
712712
this.logger.debug("Nothing to declare");
713713
return;
714714
}
715-
this.rabbitTemplate.execute(channel -> {
715+
this.rabbitTemplate.<@Nullable Object>execute(channel -> {
716716
declareExchanges(channel, exchanges.toArray(new Exchange[0]));
717717
declareQueues(channel, queues.toArray(new Queue[0]));
718718
declareBindings(channel, bindings.toArray(new Binding[0]));

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/core/RabbitOperations.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public interface RabbitOperations extends AmqpTemplate, Lifecycle {
4545
* {@link ChannelCallback#doInRabbit(com.rabbitmq.client.Channel)}.
4646
* @throws AmqpException if one occurs.
4747
*/
48-
<T> @Nullable T execute(ChannelCallback<? extends @Nullable T> action) throws AmqpException;
48+
<T extends @Nullable Object> T execute(ChannelCallback<T> action) throws AmqpException;
4949

5050
/**
5151
* Invoke the callback and run all operations on the template argument in a dedicated
@@ -57,7 +57,7 @@ public interface RabbitOperations extends AmqpTemplate, Lifecycle {
5757
* @throws AmqpException if one occurs.
5858
* @since 2.0
5959
*/
60-
default <T> @Nullable T invoke(OperationsCallback<? extends @Nullable T> action) throws AmqpException {
60+
default <T extends @Nullable Object> T invoke(OperationsCallback<T> action) throws AmqpException {
6161
return invoke(action, null, null);
6262
}
6363

@@ -71,7 +71,7 @@ public interface RabbitOperations extends AmqpTemplate, Lifecycle {
7171
* @return the result of the action method.
7272
* @since 2.1
7373
*/
74-
<T> @Nullable T invoke(OperationsCallback<? extends @Nullable T> action,
74+
<T extends @Nullable Object> T invoke(OperationsCallback<T> action,
7575
com.rabbitmq.client.@Nullable ConfirmCallback acks, com.rabbitmq.client.@Nullable ConfirmCallback nacks);
7676

7777
/**
@@ -358,8 +358,8 @@ Object convertSendAndReceive(@Nullable String exchange, @Nullable String routing
358358
* @return the response if there is one
359359
* @throws AmqpException if there is a problem
360360
*/
361-
default <T> @Nullable T convertSendAndReceiveAsType(@Nullable String exchange, @Nullable String routingKey, Object message,
362-
@Nullable CorrelationData correlationData, ParameterizedTypeReference<T> responseType)
361+
default <T> @Nullable T convertSendAndReceiveAsType(@Nullable String exchange, @Nullable String routingKey,
362+
Object message, @Nullable CorrelationData correlationData, ParameterizedTypeReference<T> responseType)
363363
throws AmqpException {
364364

365365
return convertSendAndReceiveAsType(exchange, routingKey, message, null, correlationData, responseType);
@@ -451,7 +451,7 @@ default boolean isRunning() {
451451
* @since 2.0
452452
*/
453453
@FunctionalInterface
454-
interface OperationsCallback<T> {
454+
interface OperationsCallback<T extends @Nullable Object> {
455455

456456
/**
457457
* Execute any number of operations using a dedicated
@@ -462,7 +462,6 @@ interface OperationsCallback<T> {
462462
* @param operations The operations.
463463
* @return The result.
464464
*/
465-
@Nullable
466465
T doInRabbit(RabbitOperations operations);
467466

468467
}

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/core/RabbitTemplate.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@
107107
import org.springframework.context.ApplicationContext;
108108
import org.springframework.context.ApplicationContextAware;
109109
import org.springframework.context.expression.BeanFactoryResolver;
110-
import org.springframework.context.expression.MapAccessor;
111110
import org.springframework.core.ParameterizedTypeReference;
112111
import org.springframework.core.retry.RetryException;
113112
import org.springframework.core.retry.RetryTemplate;
114113
import org.springframework.core.retry.Retryable;
115114
import org.springframework.expression.Expression;
116115
import org.springframework.expression.spel.standard.SpelExpressionParser;
116+
import org.springframework.expression.spel.support.MapAccessor;
117117
import org.springframework.expression.spel.support.StandardEvaluationContext;
118118
import org.springframework.util.Assert;
119119
import org.springframework.util.ErrorHandler;
@@ -1140,7 +1140,7 @@ public void send(@Nullable String exchange, @Nullable String routingKey,
11401140
final Message message, @Nullable CorrelationData correlationData)
11411141
throws AmqpException {
11421142

1143-
execute(channel -> {
1143+
this.<@Nullable Object>execute(channel -> {
11441144
doSend(channel, exchange, routingKey, message,
11451145
(RabbitTemplate.this.returnsCallback != null
11461146
|| (correlationData != null && StringUtils.hasText(correlationData.getId())))
@@ -1280,7 +1280,7 @@ public void convertAndSend(@Nullable String exchange, @Nullable String routingKe
12801280
* @since 1.5
12811281
*/
12821282
protected @Nullable Message doReceiveNoWait(final String queueName) {
1283-
Message message = execute(channel -> {
1283+
Message message = this.<@Nullable Message>execute(channel -> {
12841284
GetResponse response = channel.basicGet(queueName, !isChannelTransacted());
12851285
// Response can be null is the case that there is no message on the queue.
12861286
if (response != null) {
@@ -1316,7 +1316,7 @@ else if (isChannelTransacted()) {
13161316

13171317
@Override
13181318
public @Nullable Message receive(final String queueName, final long timeoutMillis) {
1319-
Message message = execute(channel -> {
1319+
Message message = this.<@Nullable Message>execute(channel -> {
13201320
Delivery delivery = consumeDelivery(channel, queueName, timeoutMillis);
13211321
if (delivery == null) {
13221322
return null;
@@ -1918,7 +1918,7 @@ else if (this.replyAddress == null || this.usingFastReplyTo) {
19181918
protected @Nullable Message doSendAndReceiveWithTemporary(@Nullable String exchange, @Nullable String routingKey,
19191919
final Message message, @Nullable CorrelationData correlationData) {
19201920

1921-
return execute(channel -> {
1921+
return this.<@Nullable Message>execute(channel -> {
19221922
final PendingReply pendingReply = new PendingReply();
19231923
String messageTag = String.valueOf(RabbitTemplate.this.messageTagProvider.incrementAndGet());
19241924
RabbitTemplate.this.replyHolder.putIfAbsent(messageTag, pendingReply);
@@ -1995,7 +1995,7 @@ private void cancelConsumerQuietly(Channel channel, DefaultConsumer consumer) {
19951995

19961996
Assert.state(this.isListener, () -> "RabbitTemplate is not configured as MessageListener - "
19971997
+ "cannot use a 'replyAddress': " + this.replyAddress);
1998-
return execute(channel ->
1998+
return this.<@Nullable Message>execute(channel ->
19991999
doSendAndReceiveAsListener(exchange, routingKey, message, correlationData, channel, false),
20002000
obtainTargetConnectionFactory(this.sendConnectionFactorySelectorExpression, message));
20012001
}
@@ -2189,12 +2189,12 @@ public Boolean isMandatoryFor(final Message message) {
21892189
}
21902190

21912191
@Override
2192-
public <T> @Nullable T execute(ChannelCallback<? extends @Nullable T> action) {
2192+
public <T extends @Nullable Object> T execute(ChannelCallback<T> action) {
21932193
return execute(action, getConnectionFactory());
21942194
}
21952195

2196-
@SuppressWarnings(UNCHECKED)
2197-
private <T> @Nullable T execute(ChannelCallback<? extends @Nullable T> action,
2196+
@SuppressWarnings({UNCHECKED, "NullAway"})
2197+
private <T extends @Nullable Object> T execute(ChannelCallback<T> action,
21982198
ConnectionFactory connectionFactory) {
21992199

22002200
if (this.retryTemplate != null) {
@@ -2214,7 +2214,7 @@ public Boolean isMandatoryFor(final Message message) {
22142214
}
22152215
}
22162216

2217-
private <T> @Nullable T doExecute(ChannelCallback<? extends @Nullable T> action,
2217+
private <T extends @Nullable Object> T doExecute(ChannelCallback<T> action,
22182218
ConnectionFactory connectionFactory) {
22192219

22202220
Assert.notNull(action, "Callback object must not be null");
@@ -2279,7 +2279,7 @@ private void cleanUpAfterAction(@Nullable Channel channel, boolean invokeScope,
22792279
}
22802280
}
22812281

2282-
private <T> @Nullable T invokeAction(ChannelCallback<? extends @Nullable T> action,
2282+
private <T extends @Nullable Object> T invokeAction(ChannelCallback<T> action,
22832283
ConnectionFactory connectionFactory, Channel channel) throws Exception {
22842284

22852285
if (isPublisherConfirmsOrReturns(connectionFactory)) {
@@ -2294,7 +2294,7 @@ private void cleanUpAfterAction(@Nullable Channel channel, boolean invokeScope,
22942294
}
22952295

22962296
@Override
2297-
public <T> @Nullable T invoke(OperationsCallback<? extends @Nullable T> action,
2297+
public <T extends @Nullable Object> T invoke(OperationsCallback<T> action,
22982298
com.rabbitmq.client.@Nullable ConfirmCallback acks, com.rabbitmq.client.@Nullable ConfirmCallback nacks) {
22992299

23002300
final Channel currentChannel = this.dedicatedChannels.get();
@@ -2906,7 +2906,7 @@ public interface RecoveryCallback {
29062906

29072907
/**
29082908
* Recover the exception that was thrown during the last attempt.
2909-
* @param lastException the exception of the last attempt
2909+
* @param lastException the exception from the last attempt
29102910
* @return Object that can be used to replace the result {@link RabbitTemplate#execute(ChannelCallback)}
29112911
*/
29122912
@Nullable

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/adapter/AbstractAdaptableMessageListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@
4343
import org.springframework.amqp.support.converter.MessageConversionException;
4444
import org.springframework.amqp.support.converter.MessageConverter;
4545
import org.springframework.amqp.support.converter.SimpleMessageConverter;
46-
import org.springframework.context.expression.MapAccessor;
4746
import org.springframework.core.retry.RetryException;
4847
import org.springframework.core.retry.RetryTemplate;
4948
import org.springframework.expression.BeanResolver;
5049
import org.springframework.expression.Expression;
5150
import org.springframework.expression.ParserContext;
5251
import org.springframework.expression.common.TemplateParserContext;
5352
import org.springframework.expression.spel.standard.SpelExpressionParser;
53+
import org.springframework.expression.spel.support.MapAccessor;
5454
import org.springframework.expression.spel.support.StandardEvaluationContext;
5555
import org.springframework.expression.spel.support.StandardTypeConverter;
5656
import org.springframework.util.Assert;
@@ -655,7 +655,7 @@ protected void sendResponse(@Nullable Channel channel, Address replyTo, Message
655655
else {
656656
final Message messageToSend = message;
657657
try {
658-
this.retryTemplate.execute(() -> {
658+
this.retryTemplate.<@Nullable Object>execute(() -> {
659659
doPublish(channel, replyTo, messageToSend);
660660
return null;
661661
});

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/retry/RepublishMessageRecovererWithConfirms.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ private void doSendCorrelated(@Nullable String exchange, String routingKey, Mess
159159
}
160160

161161
private void doSendSimple(@Nullable String exchange, String routingKey, Message message) {
162-
this.template.invoke(sender -> {
162+
this.template.<@Nullable Object>invoke(sender -> {
163163
if (exchange != null) {
164164
sender.send(exchange, routingKey, message);
165165
}

0 commit comments

Comments
 (0)