Apply "instanceof pattern matching" in remainder of spring-jms module

See gh-30067
This commit is contained in:
Sam Brannen
2023-03-06 15:32:07 +01:00
parent 7f1b81ff53
commit 09b60220d8
3 changed files with 13 additions and 11 deletions

View File

@@ -179,11 +179,14 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations
@Nullable
private Queue getDefaultQueue() {
Destination defaultDestination = getDefaultDestination();
if (defaultDestination != null && !(defaultDestination instanceof Queue)) {
if (defaultDestination == null) {
return null;
}
if (!(defaultDestination instanceof Queue queue)) {
throw new IllegalStateException(
"'defaultDestination' does not correspond to a Queue. Check configuration of JmsTemplate.");
}
return (Queue) defaultDestination;
return queue;
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -197,15 +197,15 @@ public class MessageListenerAdapter extends AbstractAdaptableMessageListener imp
* @throws JMSException if thrown by JMS API methods
*/
@Override
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
public void onMessage(Message message, @Nullable Session session) throws JMSException {
// Check whether the delegate is a MessageListener impl itself.
// In that case, the adapter will simply act as a pass-through.
Object delegate = getDelegate();
if (delegate != this) {
if (delegate instanceof SessionAwareMessageListener) {
if (delegate instanceof SessionAwareMessageListener samListener) {
Assert.state(session != null, "Session is required for SessionAwareMessageListener");
((SessionAwareMessageListener<Message>) delegate).onMessage(message, session);
samListener.onMessage(message, session);
return;
}
if (delegate instanceof MessageListener listener) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -112,14 +112,13 @@ public class MessagingMessageConverter implements MessageConverter, Initializing
return reply;
}
@SuppressWarnings("unchecked")
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public Object fromMessage(jakarta.jms.Message message) throws JMSException, MessageConversionException {
Map<String, Object> mappedHeaders = extractHeaders(message);
Object convertedObject = extractPayload(message);
MessageBuilder<Object> builder = (convertedObject instanceof org.springframework.messaging.Message ?
MessageBuilder.fromMessage((org.springframework.messaging.Message<Object>) convertedObject) :
MessageBuilder.withPayload(convertedObject));
MessageBuilder<Object> builder = (convertedObject instanceof org.springframework.messaging.Message springMessage ?
MessageBuilder.fromMessage(springMessage) : MessageBuilder.withPayload(convertedObject));
return builder.copyHeadersIfAbsent(mappedHeaders).build();
}