Fix some Sonar smells

This commit is contained in:
Artem Bilan
2020-04-08 13:01:49 -04:00
parent d8c378bd28
commit 97702ae712
7 changed files with 31 additions and 42 deletions

View File

@@ -58,9 +58,9 @@ public class ApplicationEventMulticasterParser extends AbstractSingleBeanDefinit
else {
BeanDefinitionBuilder executorBuilder =
BeanDefinitionBuilder.genericBeanDefinition(ThreadPoolTaskExecutor.class);
executorBuilder.addPropertyValue("corePoolSize", 1);
executorBuilder.addPropertyValue("maxPoolSize", 10);
executorBuilder.addPropertyValue("queueCapacity", 0);
executorBuilder.addPropertyValue("corePoolSize", 1); // NOSONAR
executorBuilder.addPropertyValue("maxPoolSize", 10); // NOSONAR
executorBuilder.addPropertyValue("queueCapacity", 0); // NOSONAR
executorBuilder.addPropertyValue("threadNamePrefix", "event-multicaster-");
builder.addPropertyValue("taskExecutor", executorBuilder.getBeanDefinition());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@@ -65,14 +65,14 @@ public class BroadcastingDispatcher extends AbstractDispatcher implements BeanFa
private volatile int minSubscribers;
private MessageHandlingTaskDecorator messageHandlingTaskDecorator = task -> task;
private BeanFactory beanFactory;
private volatile MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory();
private volatile boolean messageBuilderFactorySet;
private volatile MessageHandlingTaskDecorator messageHandlingTaskDecorator = task -> task;
private BeanFactory beanFactory;
public BroadcastingDispatcher() {
this(null, false);
@@ -226,7 +226,9 @@ public class BroadcastingDispatcher extends AbstractDispatcher implements BeanFa
}
catch (RuntimeException e) {
if (!this.ignoreFailures) {
if (e instanceof MessagingException && ((MessagingException) e).getFailedMessage() == null) {
if (e instanceof MessagingException
&& ((MessagingException) e).getFailedMessage() == null) { // NOSONAR
throw new MessagingException(message, "Failed to handle Message", e);
}
throw e;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@@ -16,6 +16,7 @@
package org.springframework.integration.dispatcher;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicInteger;
@@ -52,7 +53,7 @@ public class RoundRobinLoadBalancingStrategy implements LoadBalancingStrategy {
return handlers.iterator();
}
return this.buildHandlerIterator(size, handlers.toArray(new MessageHandler[size]));
return buildHandlerIterator(size, handlers.toArray(new MessageHandler[size]));
}
private Iterator<MessageHandler> buildHandlerIterator(int size, final MessageHandler[] handlers) {
@@ -63,23 +64,7 @@ public class RoundRobinLoadBalancingStrategy implements LoadBalancingStrategy {
System.arraycopy(handlers, nextHandlerStartIndex, reorderedHandlers, 0, size - nextHandlerStartIndex);
System.arraycopy(handlers, 0, reorderedHandlers, size - nextHandlerStartIndex, nextHandlerStartIndex);
return new Iterator<MessageHandler>() {
private int currentIndex = 0;
public boolean hasNext() {
return this.currentIndex < reorderedHandlers.length;
}
public MessageHandler next() {
return reorderedHandlers[this.currentIndex++];
}
public void remove() {
throw new UnsupportedOperationException("Remove is not supported by this Iterator");
}
};
return Arrays.stream(reorderedHandlers).iterator();
}
/**

View File

@@ -205,8 +205,7 @@ public abstract class MessageProducerSupport extends AbstractEndpoint implements
}
message = trackMessageIfAny(message);
try {
MessageChannel outputChannel = getRequiredOutputChannel();
this.messagingTemplate.send(outputChannel, message);
this.messagingTemplate.send(getRequiredOutputChannel(), message);
}
catch (RuntimeException ex) {
if (!sendErrorMessageIfNecessary(message, ex)) {
@@ -216,7 +215,7 @@ public abstract class MessageProducerSupport extends AbstractEndpoint implements
}
protected void subscribeToPublisher(Publisher<? extends Message<?>> publisher) {
MessageChannel outputChannel = getRequiredOutputChannel();
MessageChannel channelForSubscription = getRequiredOutputChannel();
Flux<? extends Message<?>> messageFlux =
Flux.from(publisher)
@@ -225,8 +224,8 @@ public abstract class MessageProducerSupport extends AbstractEndpoint implements
.doOnCancel(this::stop)
.takeWhile((message) -> isRunning());
if (outputChannel instanceof ReactiveStreamsSubscribableChannel) {
((ReactiveStreamsSubscribableChannel) outputChannel).subscribeTo(messageFlux);
if (channelForSubscription instanceof ReactiveStreamsSubscribableChannel) {
((ReactiveStreamsSubscribableChannel) channelForSubscription).subscribeTo(messageFlux);
}
else {
messageFlux

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@@ -52,13 +52,18 @@ import org.springframework.util.CollectionUtils;
*/
public class PollingConsumer extends AbstractPollingEndpoint implements IntegrationConsumer {
/**
* A default receive timeout as {@value DEFAULT_RECEIVE_TIMEOUT} milliseconds.
*/
public static final long DEFAULT_RECEIVE_TIMEOUT = 1000;
private final PollableChannel inputChannel;
private final MessageHandler handler;
private final List<ChannelInterceptor> channelInterceptors;
private volatile long receiveTimeout = 1000;
private volatile long receiveTimeout = DEFAULT_RECEIVE_TIMEOUT;
public PollingConsumer(PollableChannel inputChannel, MessageHandler handler) {
Assert.notNull(inputChannel, "inputChannel must not be null");

View File

@@ -236,7 +236,7 @@ public class SourcePollingChannelAdapter extends AbstractPollingEndpoint
}
catch (Exception e) {
AckUtils.autoNack(ackCallback);
if (e instanceof MessagingException) {
if (e instanceof MessagingException) { // NOSONAR
throw (MessagingException) e;
}
else {