Skip to content

Commit d07dba4

Browse files
committed
Address PR comments
Signed-off-by: Jiandong Ma <[email protected]>
1 parent 2431118 commit d07dba4

File tree

5 files changed

+27
-19
lines changed

5 files changed

+27
-19
lines changed

spring-integration-jms/src/main/java/org/springframework/integration/jms/ChannelPublishingJmsMessageListener.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.integration.jms;
1818

1919
import java.util.Map;
20+
import java.util.Objects;
2021
import java.util.concurrent.atomic.AtomicInteger;
2122

2223
import io.micrometer.observation.ObservationRegistry;
@@ -114,7 +115,8 @@ public class ChannelPublishingJmsMessageListener
114115

115116
private JmsHeaderMapper headerMapper = new DefaultJmsHeaderMapper();
116117

117-
private @Nullable BeanFactory beanFactory;
118+
@SuppressWarnings("NullAway.Init")
119+
private BeanFactory beanFactory;
118120

119121
private MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory();
120122

@@ -175,8 +177,8 @@ public void setShouldTrack(boolean shouldTrack) {
175177
}
176178

177179
@Override
178-
public @Nullable String getComponentName() {
179-
return this.gatewayDelegate.getComponentName();
180+
public String getComponentName() {
181+
return Objects.requireNonNull(this.gatewayDelegate.getComponentName());
180182
}
181183

182184
@Override

spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsInboundGateway.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.integration.jms;
1818

19+
import java.util.Objects;
20+
1921
import io.micrometer.observation.ObservationRegistry;
2022
import org.jspecify.annotations.Nullable;
2123

@@ -157,8 +159,7 @@ public void setBeanFactory(BeanFactory beanFactory) {
157159

158160
@Override
159161
protected void onInit() {
160-
String componentName = getComponentName();
161-
this.endpoint.setComponentName(componentName == null ? "jms-inbound-gateway" : componentName);
162+
this.endpoint.setComponentName(Objects.requireNonNull(getComponentName()));
162163
this.endpoint.afterPropertiesSet();
163164
}
164165

spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsMessageDrivenEndpoint.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.integration.jms;
1818

19+
import java.util.Objects;
20+
1921
import io.micrometer.observation.ObservationRegistry;
2022
import org.jspecify.annotations.Nullable;
2123

@@ -219,8 +221,7 @@ protected void onInit() {
219221
this.listenerContainer.setSessionAcknowledgeMode(acknowledgeMode);
220222
}
221223
}
222-
String componentName = getComponentName();
223-
this.listener.setComponentName(componentName == null ? "jms-message-listener" : componentName);
224+
this.listener.setComponentName(Objects.requireNonNull(getComponentName()));
224225
}
225226

226227
@Override

spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsOutboundGateway.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.Iterator;
2222
import java.util.Map;
2323
import java.util.Map.Entry;
24-
import java.util.Objects;
2524
import java.util.UUID;
2625
import java.util.concurrent.CompletableFuture;
2726
import java.util.concurrent.ConcurrentHashMap;
@@ -753,7 +752,7 @@ public boolean isRunning() {
753752
this.replyContainer.start();
754753
this.idleTask =
755754
getTaskScheduler()
756-
.scheduleAtFixedRate(new IdleContainerStopper(),
755+
.scheduleAtFixedRate(new IdleContainerStopper(this.replyContainer),
757756
Duration.ofMillis(this.idleReplyContainerTimeout / 2));
758757
}
759758
}
@@ -809,10 +808,10 @@ private AbstractIntegrationMessageBuilder<?> buildReply(jakarta.jms.Message jmsR
809808
}
810809
}
811810

811+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
812812
private @Nullable Object sendAndReceiveWithContainer(Message<?> requestMessage) throws JMSException {
813813
Connection connection = createConnection(); // NOSONAR - closed in ConnectionFactoryUtils.
814814
Session session = null;
815-
Assert.notNull(this.replyContainer, "'replyContainer' must not be null");
816815
Destination replyTo = this.replyContainer.getReplyDestination();
817816
try {
818817
session = createSession(connection);
@@ -1074,6 +1073,7 @@ else if (replyTo instanceof TemporaryQueue || replyTo instanceof TemporaryTopic)
10741073
}
10751074
}
10761075

1076+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
10771077
private @Nullable Object doSendAndReceiveAsync(Destination reqDestination, jakarta.jms.Message jmsRequest, Session session,
10781078
int priority) throws JMSException {
10791079

@@ -1082,7 +1082,6 @@ else if (replyTo instanceof TemporaryQueue || replyTo instanceof TemporaryTopic)
10821082
try {
10831083
messageProducer = session.createProducer(reqDestination);
10841084
correlation = this.gatewayCorrelation + "_" + this.correlationId.incrementAndGet();
1085-
Assert.notNull(this.correlationKey, "'correlationKey' must not be null");
10861085
if (this.correlationKey.equals("JMSCorrelationID")) {
10871086
jmsRequest.setJMSCorrelationID(correlation);
10881087
}
@@ -1113,7 +1112,7 @@ else if (replyTo instanceof TemporaryQueue || replyTo instanceof TemporaryTopic)
11131112
return future;
11141113
}
11151114
else {
1116-
return obtainReplyFromContainer(correlation, Objects.requireNonNull(replyQueue));
1115+
return obtainReplyFromContainer(correlation, replyQueue);
11171116
}
11181117
}
11191118
finally {
@@ -1495,7 +1494,10 @@ public void run() {
14951494

14961495
private class IdleContainerStopper implements Runnable {
14971496

1498-
IdleContainerStopper() {
1497+
private final GatewayReplyListenerContainer replyContainer;
1498+
1499+
IdleContainerStopper(GatewayReplyListenerContainer replyContainer) {
1500+
this.replyContainer = replyContainer;
14991501
}
15001502

15011503
@Override
@@ -1505,11 +1507,14 @@ public void run() {
15051507
if (System.currentTimeMillis() - JmsOutboundGateway.this.lastSend >
15061508
JmsOutboundGateway.this.idleReplyContainerTimeout
15071509
&& JmsOutboundGateway.this.replies.isEmpty() &&
1508-
Objects.requireNonNull(JmsOutboundGateway.this.replyContainer).isRunning()) {
1510+
this.replyContainer.isRunning()) {
15091511

15101512
logger.debug(() -> getComponentName() + ": Stopping idle reply container.");
1511-
JmsOutboundGateway.this.replyContainer.stop();
1512-
Objects.requireNonNull(JmsOutboundGateway.this.idleTask).cancel(false);
1513+
this.replyContainer.stop();
1514+
ScheduledFuture<?> idleTask = JmsOutboundGateway.this.idleTask;
1515+
if (idleTask != null) {
1516+
idleTask.cancel(false);
1517+
}
15131518
JmsOutboundGateway.this.idleTask = null;
15141519
}
15151520
}

spring-integration-jms/src/main/java/org/springframework/integration/jms/SubscribableJmsChannel.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ private static final class DispatchingMessageListener implements MessageListener
209209
this.messageBuilderFactory = messageBuilderFactory;
210210
}
211211

212+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
212213
@Override
213214
public void onMessage(jakarta.jms.Message message) {
214215
Message<?> messageToSend = null;
@@ -240,9 +241,7 @@ else if (this.logger.isWarnEnabled()) {
240241
}
241242
}
242243
else {
243-
throw messageToSend != null
244-
? new MessageDeliveryException(messageToSend, exceptionMessage, e)
245-
: new MessageDeliveryException(exceptionMessage);
244+
throw new MessageDeliveryException(messageToSend, exceptionMessage, e);
246245
}
247246
}
248247
catch (Exception e) {

0 commit comments

Comments
 (0)