Skip to content

Commit c1c3e76

Browse files
committed
Adjust PR to resolve code review issues
* In code segments where performance is critical remove null checks and suppress warnings. * Format code to improve readability * Cleanup some Nullable's in a couple locations Continued effort or issue: #10083
1 parent 42d7b18 commit c1c3e76

File tree

7 files changed

+16
-25
lines changed

7 files changed

+16
-25
lines changed

spring-integration-amqp/src/main/java/org/springframework/integration/amqp/channel/PollableAmqpChannel.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.util.Deque;
2121
import java.util.List;
2222
import java.util.Map;
23-
import java.util.Objects;
2423
import java.util.concurrent.atomic.AtomicBoolean;
2524

2625
import org.jspecify.annotations.Nullable;
@@ -328,7 +327,7 @@ public ChannelInterceptor removeInterceptor(int index) {
328327
if (interceptor instanceof ExecutorChannelInterceptor) {
329328
this.executorInterceptorsSize--;
330329
}
331-
return Objects.requireNonNull(interceptor);
330+
return interceptor;
332331
}
333332

334333
@Override

spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractExecutorChannel.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ public abstract class AbstractExecutorChannel extends AbstractSubscribableChanne
6161

6262
protected @Nullable Executor executor;
6363

64-
/**
65-
* {@code @SuppressWarnings} was used the dispatcher is initialized in each of the implementations in the {@link AbstractExecutorChannel}. And each implementation
66-
* utilizes a unique implementation of the {@link AbstractDispatcher}.
67-
*/
6864
@SuppressWarnings("NullAway.Init")
6965
protected AbstractDispatcher dispatcher;
7066

spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.util.Deque;
2525
import java.util.Iterator;
2626
import java.util.List;
27-
import java.util.Objects;
2827
import java.util.Set;
2928
import java.util.concurrent.ConcurrentHashMap;
3029
import java.util.concurrent.CopyOnWriteArrayList;
@@ -236,7 +235,7 @@ public boolean removeInterceptor(ChannelInterceptor interceptor) {
236235

237236
@Override
238237
public ChannelInterceptor removeInterceptor(int index) {
239-
return Objects.requireNonNull(this.interceptors.remove(index));
238+
return this.interceptors.remove(index);
240239
}
241240

242241
/**
@@ -391,17 +390,18 @@ private boolean sendWithObservation(Message<?> message, long timeout) {
391390
Message<?> messageToSendInternal = messageToSend;
392391
if (message instanceof ErrorMessage errorMessage) {
393392
messageToSendInternal =
394-
new ErrorMessage(errorMessage.getPayload(),
393+
(errorMessage.getOriginalMessage() != null) ? new ErrorMessage(errorMessage.getPayload(),
395394
messageToSend.getHeaders(),
396-
Objects.requireNonNull(errorMessage.getOriginalMessage()));
395+
errorMessage.getOriginalMessage()) : new ErrorMessage(errorMessage.getPayload(),
396+
messageToSend.getHeaders());
397397
}
398398
return sendInternal(messageToSendInternal, timeout);
399399
});
400400
return Boolean.TRUE.equals(observe);
401401
}
402402

403+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
403404
private boolean sendWithMetrics(Message<?> message, long timeout) {
404-
Assert.state(this.metricsCaptor != null, "The metricsCaptor must not be null");
405405
SampleFacade sample = this.metricsCaptor.start();
406406
try {
407407
boolean sent = sendInternal(message, timeout);
@@ -468,8 +468,8 @@ private TimerFacade sendTimer(boolean sent) {
468468
}
469469
}
470470

471+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
471472
private TimerFacade buildSendTimer(boolean success, String exception) {
472-
Assert.state(this.metricsCaptor != null, "The metricsCaptor must not be null");
473473
TimerFacade timer = this.metricsCaptor.timerBuilder(SEND_TIMER_NAME)
474474
.tag("type", "channel")
475475
.tag("name", getComponentName() == null ? "unknown" : getComponentName())
@@ -677,7 +677,6 @@ public boolean remove(ChannelInterceptor interceptor) {
677677
}
678678
}
679679

680-
@Nullable
681680
public ChannelInterceptor remove(int index) {
682681
ChannelInterceptor removed = this.interceptors.remove(index);
683682
if (removed != null) {

spring-integration-core/src/main/java/org/springframework/integration/channel/MessagePublishingErrorHandler.java

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

1717
package org.springframework.integration.channel;
1818

19-
import java.util.Objects;
20-
2119
import org.jspecify.annotations.Nullable;
2220

2321
import org.springframework.integration.context.IntegrationContextUtils;
@@ -47,10 +45,11 @@ public class MessagePublishingErrorHandler extends ErrorMessagePublisher impleme
4745

4846
private static final int DEFAULT_SEND_TIMEOUT = 1000;
4947

48+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
5049
private static final ErrorMessageStrategy DEFAULT_ERROR_MESSAGE_STRATEGY = (ex, attrs) -> {
51-
if (ex instanceof MessagingExceptionWrapper) {
52-
return new ErrorMessage(Objects.requireNonNull(ex.getCause()),
53-
Objects.requireNonNull(((MessagingExceptionWrapper) ex).getFailedMessage()));
50+
if (ex instanceof MessagingExceptionWrapper messagingExceptionWrapper) {
51+
return new ErrorMessage(messagingExceptionWrapper.getCause(),
52+
messagingExceptionWrapper.getFailedMessage());
5453
}
5554
else {
5655
return new ErrorMessage(ex);
@@ -69,7 +68,7 @@ public MessagePublishingErrorHandler(DestinationResolver<MessageChannel> channel
6968
setChannelResolver(channelResolver);
7069
}
7170

72-
public void setDefaultErrorChannel(@Nullable MessageChannel defaultErrorChannel) {
71+
public void setDefaultErrorChannel(MessageChannel defaultErrorChannel) {
7372
setChannel(defaultErrorChannel);
7473
}
7574

spring-integration-core/src/main/java/org/springframework/integration/channel/NullChannel.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.springframework.integration.support.management.metrics.TimerFacade;
3535
import org.springframework.messaging.Message;
3636
import org.springframework.messaging.PollableChannel;
37-
import org.springframework.util.Assert;
3837

3938
/**
4039
* A channel implementation that essentially behaves like "/dev/null".
@@ -163,9 +162,9 @@ public void onComplete() {
163162
return true;
164163
}
165164

165+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
166166
private TimerFacade sendTimer() {
167167
if (this.successTimer == null) {
168-
Assert.state(this.metricsCaptor != null, "metricsCaptor not must not be null");
169168
this.successTimer =
170169
this.metricsCaptor.timerBuilder(SEND_TIMER_NAME)
171170
.tag("type", "channel")
@@ -201,8 +200,8 @@ private void incrementReceiveCounter() {
201200
}
202201
}
203202

203+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
204204
private CounterFacade buildReceiveCounter() {
205-
Assert.state(this.metricsCaptor != null, "metricsCaptor not must not be null");
206205
return this.metricsCaptor
207206
.counterBuilder(RECEIVE_COUNTER_NAME)
208207
.tag("name", getComponentName() == null ? "unknown" : getComponentName())

spring-integration-core/src/main/java/org/springframework/integration/channel/PartitionedChannel.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ public class PartitionedChannel extends AbstractExecutorChannel {
6666
* sent to this channel.
6767
*/
6868
public PartitionedChannel(int partitionCount) {
69-
this(partitionCount, (message) -> Objects.requireNonNull(
70-
message.getHeaders().get(IntegrationMessageHeaderAccessor.CORRELATION_ID)));
69+
this(partitionCount, (message) -> Objects.requireNonNull(message.getHeaders().get(IntegrationMessageHeaderAccessor.CORRELATION_ID)));
7170
}
7271

7372
/**

spring-integration-core/src/main/java/org/springframework/integration/core/ErrorMessagePublisher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public final void setErrorMessageStrategy(ErrorMessageStrategy errorMessageStrat
7070
this.errorMessageStrategy = errorMessageStrategy;
7171
}
7272

73-
public final void setChannel(@Nullable MessageChannel channel) {
73+
public final void setChannel(MessageChannel channel) {
7474
this.channel = channel;
7575
}
7676

0 commit comments

Comments
 (0)