Sonar fixes

* use equals
* inner assignment
* local before return
* unnecessary locals
* catch and throw
* uninstantiable with no statics
* implement `Serializable` in `Comparator` to enable `TreeMap` serialization
* exceptions as flow control
This commit is contained in:
Gary Russell
2019-04-30 15:32:41 -04:00
committed by Artem Bilan
parent 130e1bba31
commit 19b9944dd8
31 changed files with 98 additions and 87 deletions

View File

@@ -108,6 +108,7 @@ public class CorrelatingMessageBarrier extends AbstractMessageHandler implements
}
@SuppressWarnings("unchecked")
@Override
public Message<Object> receive() {
for (Object key : this.correlationLocks.keySet()) {
@@ -130,9 +131,7 @@ public class CorrelatingMessageBarrier extends AbstractMessageHandler implements
else {
remove(key);
}
@SuppressWarnings("unchecked")
Message<Object> result = (Message<Object>) nextMessage;
return result;
return (Message<Object>) nextMessage;
}
}
}

View File

@@ -16,6 +16,7 @@
package org.springframework.integration.aggregator;
import java.io.Serializable;
import java.util.Comparator;
import org.springframework.integration.IntegrationMessageHeaderAccessor;
@@ -25,8 +26,10 @@ import org.springframework.messaging.Message;
* @author Mark Fisher
* @author Dave Syer
* @author Artem Bilan
* @author Gary Russell
*/
public class MessageSequenceComparator implements Comparator<Message<?>> {
@SuppressWarnings("serial")
public class MessageSequenceComparator implements Comparator<Message<?>>, Serializable {
@Override
public int compare(Message<?> o1, Message<?> o2) {

View File

@@ -193,7 +193,7 @@ public class PublisherAnnotationAdvisor extends AbstractPointcutAdvisor implemen
}
// The method may be on an interface, so let's check on the target class as well.
Method specificMethod = AopUtils.getMostSpecificMethod(method, targetClass);
return (specificMethod != method &&
return (!specificMethod.equals(method) &&
(AnnotationUtils.getAnnotation(specificMethod, this.annotationType) != null));
}

View File

@@ -106,7 +106,8 @@ public final class MessageChannelReactiveUtils {
.<Message<T>>create(sink ->
sink.onRequest(n -> {
Message<?> m;
while (!sink.isCancelled() && n-- > 0 && (m = this.channel.receive()) != null) {
while (!sink.isCancelled() && n-- > 0
&& (m = this.channel.receive()) != null) { // NOSONAR
sink.next((Message<T>) m);
}
}),

View File

@@ -39,7 +39,7 @@ public final class FixedSubscriberChannelBeanFactoryPostProcessor implements Bea
private final Map<String, String> candidateFixedChannelHandlerMap;
private FixedSubscriberChannelBeanFactoryPostProcessor(Map<String, String> candidateHandlers) {
FixedSubscriberChannelBeanFactoryPostProcessor(Map<String, String> candidateHandlers) {
this.candidateFixedChannelHandlerMap = candidateHandlers;
}

View File

@@ -158,7 +158,7 @@ public abstract class AbstractMethodAnnotationPostProcessor<T extends Annotation
orderable(method, handler);
producerOrRouter(annotations, handler);
if (handler != sourceHandler) {
if (!handler.equals(sourceHandler)) {
String handlerBeanName = generateHandlerBeanName(beanName, method);
if (handler instanceof ReplyProducingMessageHandlerWrapper
&& StringUtils.hasText(MessagingAnnotationUtils.endpointIdValue(method))) {

View File

@@ -52,7 +52,7 @@ public class PointToPointChannelParser extends AbstractChannelParser {
// configure a queue-based channel if any queue sub-element is defined
String channel = element.getAttribute(ID_ATTRIBUTE);
if ((queueElement = DomUtils.getChildElementByTagName(element, "queue")) != null) {
if ((queueElement = DomUtils.getChildElementByTagName(element, "queue")) != null) { // NOSONAR inner assignment
builder = BeanDefinitionBuilder.genericBeanDefinition(QueueChannel.class);
boolean hasStoreRef = this.parseStoreRef(builder, queueElement, channel, false);
boolean hasQueueRef = this.parseQueueRef(builder, queueElement);
@@ -76,7 +76,7 @@ public class PointToPointChannelParser extends AbstractChannelParser {
element);
}
}
else if ((queueElement = DomUtils.getChildElementByTagName(element, "priority-queue")) != null) {
else if ((queueElement = DomUtils.getChildElementByTagName(element, "priority-queue")) != null) { // NOSONAR
builder = BeanDefinitionBuilder.genericBeanDefinition(PriorityChannel.class);
boolean hasCapacity = this.parseQueueCapacity(builder, queueElement);
String comparatorRef = queueElement.getAttribute("comparator");
@@ -97,7 +97,7 @@ public class PointToPointChannelParser extends AbstractChannelParser {
}
}
else if ((queueElement = DomUtils.getChildElementByTagName(element, "rendezvous-queue")) != null) {
else if ((queueElement = DomUtils.getChildElementByTagName(element, "rendezvous-queue")) != null) { // NOSONAR
builder = BeanDefinitionBuilder.genericBeanDefinition(RendezvousChannel.class);
}

View File

@@ -35,6 +35,7 @@ import org.springframework.util.StringUtils;
*
* @author Mark Fisher
* @author Iwein Fuld
* @author Gary Russell
*/
public class SelectorChainParser extends AbstractSingleBeanDefinitionParser {
@@ -43,6 +44,7 @@ public class SelectorChainParser extends AbstractSingleBeanDefinitionParser {
return MessageSelectorChain.class.getName();
}
@Override
public void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
if (!StringUtils.hasText(element.getAttribute("id"))) {
parserContext.getReaderContext().error("id is required", element);
@@ -82,8 +84,7 @@ public class SelectorChainParser extends AbstractSingleBeanDefinitionParser {
this.parseSelectorChain(nestedBuilder, (Element) child, parserContext);
String nestedBeanName = BeanDefinitionReaderUtils.registerWithGeneratedName(nestedBuilder.getBeanDefinition(),
parserContext.getRegistry());
RuntimeBeanReference built = new RuntimeBeanReference(nestedBeanName);
return built;
return new RuntimeBeanReference(nestedBeanName);
}
private RuntimeBeanReference buildMethodInvokingSelector(ParserContext parserContext, String ref, String method) {

View File

@@ -59,7 +59,7 @@ public final class StandardIntegrationFlowContext implements IntegrationFlowCont
private BeanDefinitionRegistry beanDefinitionRegistry;
private StandardIntegrationFlowContext() {
StandardIntegrationFlowContext() {
}
@Override

View File

@@ -137,7 +137,7 @@ public class RecipientListRouter extends AbstractMessageRouter implements Recipi
addRecipient(channelName, selectorExpression, this.recipients);
}
private void addRecipient(String channelName, String selectorExpression, Queue<Recipient> recipients) {
private void addRecipient(String channelName, String selectorExpression, Queue<Recipient> recipientsToAdd) {
Assert.hasText(channelName, "'channelName' must not be empty.");
Assert.hasText(selectorExpression, "'selectorExpression' must not be empty.");
ExpressionEvaluatingSelector expressionEvaluatingSelector =
@@ -145,7 +145,7 @@ public class RecipientListRouter extends AbstractMessageRouter implements Recipi
expressionEvaluatingSelector.setBeanFactory(getBeanFactory());
Recipient recipient = new Recipient(channelName, expressionEvaluatingSelector);
setupRecipient(recipient);
recipients.add(recipient);
recipientsToAdd.add(recipient);
}
@Override
@@ -158,11 +158,11 @@ public class RecipientListRouter extends AbstractMessageRouter implements Recipi
addRecipient(channelName, selector, this.recipients);
}
private void addRecipient(String channelName, MessageSelector selector, Queue<Recipient> recipients) {
private void addRecipient(String channelName, MessageSelector selector, Queue<Recipient> recipientsToAdd) {
Assert.hasText(channelName, "'channelName' must not be empty.");
Recipient recipient = new Recipient(channelName, selector);
setupRecipient(recipient);
recipients.add(recipient);
recipientsToAdd.add(recipient);
}
public void addRecipient(MessageChannel channel) {
@@ -208,9 +208,9 @@ public class RecipientListRouter extends AbstractMessageRouter implements Recipi
Recipient next = it.next();
MessageSelector selector = next.getSelector();
MessageChannel channel = next.getChannel();
if (selector instanceof ExpressionEvaluatingSelector &&
channel == targetChannel &&
((ExpressionEvaluatingSelector) selector).getExpressionString().equals(selectorExpression)) {
if (selector instanceof ExpressionEvaluatingSelector
&& channel.equals(targetChannel)
&& ((ExpressionEvaluatingSelector) selector).getExpressionString().equals(selectorExpression)) {
it.remove();
counter++;
}

View File

@@ -37,7 +37,7 @@ public abstract class AbstractTransformer extends IntegrationObjectSupport imple
return (result instanceof Message) ? (Message<?>) result
: this.getMessageBuilderFactory().withPayload(result).copyHeaders(message.getHeaders()).build();
}
catch (MessageTransformationException e) {
catch (MessageTransformationException e) { // NOSONAR - catch and throw
throw e;
}
catch (Exception e) {