Skip to content

Commit 97702ae

Browse files
committed
Fix some Sonar smells
1 parent d8c378b commit 97702ae

File tree

7 files changed

+31
-42
lines changed

7 files changed

+31
-42
lines changed

spring-integration-core/src/main/java/org/springframework/integration/config/xml/ApplicationEventMulticasterParser.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ protected void doParse(Element element, ParserContext parserContext, BeanDefinit
5858
else {
5959
BeanDefinitionBuilder executorBuilder =
6060
BeanDefinitionBuilder.genericBeanDefinition(ThreadPoolTaskExecutor.class);
61-
executorBuilder.addPropertyValue("corePoolSize", 1);
62-
executorBuilder.addPropertyValue("maxPoolSize", 10);
63-
executorBuilder.addPropertyValue("queueCapacity", 0);
61+
executorBuilder.addPropertyValue("corePoolSize", 1); // NOSONAR
62+
executorBuilder.addPropertyValue("maxPoolSize", 10); // NOSONAR
63+
executorBuilder.addPropertyValue("queueCapacity", 0); // NOSONAR
6464
executorBuilder.addPropertyValue("threadNamePrefix", "event-multicaster-");
6565
builder.addPropertyValue("taskExecutor", executorBuilder.getBeanDefinition());
6666
}

spring-integration-core/src/main/java/org/springframework/integration/dispatcher/BroadcastingDispatcher.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -65,13 +65,13 @@ public class BroadcastingDispatcher extends AbstractDispatcher implements BeanFa
6565

6666
private volatile int minSubscribers;
6767

68-
private volatile MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory();
68+
private MessageHandlingTaskDecorator messageHandlingTaskDecorator = task -> task;
6969

70-
private volatile boolean messageBuilderFactorySet;
70+
private BeanFactory beanFactory;
7171

72-
private volatile MessageHandlingTaskDecorator messageHandlingTaskDecorator = task -> task;
72+
private volatile MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory();
7373

74-
private BeanFactory beanFactory;
74+
private volatile boolean messageBuilderFactorySet;
7575

7676

7777
public BroadcastingDispatcher() {
@@ -226,7 +226,9 @@ private boolean invokeHandler(MessageHandler handler, Message<?> message) {
226226
}
227227
catch (RuntimeException e) {
228228
if (!this.ignoreFailures) {
229-
if (e instanceof MessagingException && ((MessagingException) e).getFailedMessage() == null) {
229+
if (e instanceof MessagingException
230+
&& ((MessagingException) e).getFailedMessage() == null) { // NOSONAR
231+
230232
throw new MessagingException(message, "Failed to handle Message", e);
231233
}
232234
throw e;

spring-integration-core/src/main/java/org/springframework/integration/dispatcher/RoundRobinLoadBalancingStrategy.java

+4-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.integration.dispatcher;
1818

19+
import java.util.Arrays;
1920
import java.util.Collection;
2021
import java.util.Iterator;
2122
import java.util.concurrent.atomic.AtomicInteger;
@@ -52,7 +53,7 @@ public final Iterator<MessageHandler> getHandlerIterator(Message<?> message, Col
5253
return handlers.iterator();
5354
}
5455

55-
return this.buildHandlerIterator(size, handlers.toArray(new MessageHandler[size]));
56+
return buildHandlerIterator(size, handlers.toArray(new MessageHandler[size]));
5657
}
5758

5859
private Iterator<MessageHandler> buildHandlerIterator(int size, final MessageHandler[] handlers) {
@@ -63,23 +64,7 @@ private Iterator<MessageHandler> buildHandlerIterator(int size, final MessageHan
6364
System.arraycopy(handlers, nextHandlerStartIndex, reorderedHandlers, 0, size - nextHandlerStartIndex);
6465
System.arraycopy(handlers, 0, reorderedHandlers, size - nextHandlerStartIndex, nextHandlerStartIndex);
6566

66-
return new Iterator<MessageHandler>() {
67-
68-
private int currentIndex = 0;
69-
70-
public boolean hasNext() {
71-
return this.currentIndex < reorderedHandlers.length;
72-
}
73-
74-
public MessageHandler next() {
75-
return reorderedHandlers[this.currentIndex++];
76-
}
77-
78-
public void remove() {
79-
throw new UnsupportedOperationException("Remove is not supported by this Iterator");
80-
}
81-
82-
};
67+
return Arrays.stream(reorderedHandlers).iterator();
8368
}
8469

8570
/**

spring-integration-core/src/main/java/org/springframework/integration/endpoint/MessageProducerSupport.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,7 @@ protected void sendMessage(Message<?> messageArg) {
205205
}
206206
message = trackMessageIfAny(message);
207207
try {
208-
MessageChannel outputChannel = getRequiredOutputChannel();
209-
this.messagingTemplate.send(outputChannel, message);
208+
this.messagingTemplate.send(getRequiredOutputChannel(), message);
210209
}
211210
catch (RuntimeException ex) {
212211
if (!sendErrorMessageIfNecessary(message, ex)) {
@@ -216,7 +215,7 @@ protected void sendMessage(Message<?> messageArg) {
216215
}
217216

218217
protected void subscribeToPublisher(Publisher<? extends Message<?>> publisher) {
219-
MessageChannel outputChannel = getRequiredOutputChannel();
218+
MessageChannel channelForSubscription = getRequiredOutputChannel();
220219

221220
Flux<? extends Message<?>> messageFlux =
222221
Flux.from(publisher)
@@ -225,8 +224,8 @@ protected void subscribeToPublisher(Publisher<? extends Message<?>> publisher) {
225224
.doOnCancel(this::stop)
226225
.takeWhile((message) -> isRunning());
227226

228-
if (outputChannel instanceof ReactiveStreamsSubscribableChannel) {
229-
((ReactiveStreamsSubscribableChannel) outputChannel).subscribeTo(messageFlux);
227+
if (channelForSubscription instanceof ReactiveStreamsSubscribableChannel) {
228+
((ReactiveStreamsSubscribableChannel) channelForSubscription).subscribeTo(messageFlux);
230229
}
231230
else {
232231
messageFlux

spring-integration-core/src/main/java/org/springframework/integration/endpoint/PollingConsumer.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -52,13 +52,18 @@
5252
*/
5353
public class PollingConsumer extends AbstractPollingEndpoint implements IntegrationConsumer {
5454

55+
/**
56+
* A default receive timeout as {@value DEFAULT_RECEIVE_TIMEOUT} milliseconds.
57+
*/
58+
public static final long DEFAULT_RECEIVE_TIMEOUT = 1000;
59+
5560
private final PollableChannel inputChannel;
5661

5762
private final MessageHandler handler;
5863

5964
private final List<ChannelInterceptor> channelInterceptors;
6065

61-
private volatile long receiveTimeout = 1000;
66+
private volatile long receiveTimeout = DEFAULT_RECEIVE_TIMEOUT;
6267

6368
public PollingConsumer(PollableChannel inputChannel, MessageHandler handler) {
6469
Assert.notNull(inputChannel, "inputChannel must not be null");

spring-integration-core/src/main/java/org/springframework/integration/endpoint/SourcePollingChannelAdapter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ protected void handleMessage(Message<?> messageArg) {
236236
}
237237
catch (Exception e) {
238238
AckUtils.autoNack(ackCallback);
239-
if (e instanceof MessagingException) {
239+
if (e instanceof MessagingException) { // NOSONAR
240240
throw (MessagingException) e;
241241
}
242242
else {

spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/inbound/MongoDbChangeStreamMessageProducer.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
package org.springframework.integration.mongodb.inbound;
1818

1919
import org.bson.Document;
20-
import org.reactivestreams.Publisher;
2120

22-
import org.springframework.data.mongodb.core.ChangeStreamEvent;
2321
import org.springframework.data.mongodb.core.ChangeStreamOptions;
2422
import org.springframework.data.mongodb.core.ReactiveMongoOperations;
2523
import org.springframework.integration.endpoint.MessageProducerSupport;
@@ -35,7 +33,7 @@
3533
* A {@link MessageProducerSupport} for MongoDB Change Stream implementation.
3634
* The functionality is based on the
3735
* {@link ReactiveMongoOperations#changeStream(String, ChangeStreamOptions, Class)}
38-
* and {@link MessageProducerSupport#subscribeToPublisher(Publisher)} consumption.
36+
* and {@link MessageProducerSupport#subscribeToPublisher(org.reactivestreams.Publisher)} consumption.
3937
*
4038
* @author Artem Bilan
4139
*
@@ -97,9 +95,9 @@ public void setOptions(ChangeStreamOptions options) {
9795

9896
/**
9997
* Configure this channel adapter to build a {@link Message} to produce
100-
* with a payload based on a {@link ChangeStreamEvent#getBody()} (by default)
101-
* or use a whole {@link ChangeStreamEvent} as a payload.
102-
* @param extractBody to extract {@link ChangeStreamEvent#getBody()} or not.
98+
* with a payload based on a {@link org.springframework.data.mongodb.core.ChangeStreamEvent#getBody()} (by default)
99+
* or use a whole {@link org.springframework.data.mongodb.core.ChangeStreamEvent} as a payload.
100+
* @param extractBody to extract {@link org.springframework.data.mongodb.core.ChangeStreamEvent#getBody()} or not.
103101
*/
104102
public void setExtractBody(boolean extractBody) {
105103
this.extractBody = extractBody;

0 commit comments

Comments
 (0)