Skip to content

Commit 19b9944

Browse files
garyrussellartembilan
authored andcommitted
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
1 parent 130e1bb commit 19b9944

File tree

31 files changed

+98
-87
lines changed

31 files changed

+98
-87
lines changed

spring-integration-core/src/main/java/org/springframework/integration/aggregator/CorrelatingMessageBarrier.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ private Object getLock(Object correlationKey) {
108108
}
109109

110110

111+
@SuppressWarnings("unchecked")
111112
@Override
112113
public Message<Object> receive() {
113114
for (Object key : this.correlationLocks.keySet()) {
@@ -130,9 +131,7 @@ public Message<Object> receive() {
130131
else {
131132
remove(key);
132133
}
133-
@SuppressWarnings("unchecked")
134-
Message<Object> result = (Message<Object>) nextMessage;
135-
return result;
134+
return (Message<Object>) nextMessage;
136135
}
137136
}
138137
}

spring-integration-core/src/main/java/org/springframework/integration/aggregator/MessageSequenceComparator.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.integration.aggregator;
1818

19+
import java.io.Serializable;
1920
import java.util.Comparator;
2021

2122
import org.springframework.integration.IntegrationMessageHeaderAccessor;
@@ -25,8 +26,10 @@
2526
* @author Mark Fisher
2627
* @author Dave Syer
2728
* @author Artem Bilan
29+
* @author Gary Russell
2830
*/
29-
public class MessageSequenceComparator implements Comparator<Message<?>> {
31+
@SuppressWarnings("serial")
32+
public class MessageSequenceComparator implements Comparator<Message<?>>, Serializable {
3033

3134
@Override
3235
public int compare(Message<?> o1, Message<?> o2) {

spring-integration-core/src/main/java/org/springframework/integration/aop/PublisherAnnotationAdvisor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public boolean matches(Method method, Class<?> targetClass) {
193193
}
194194
// The method may be on an interface, so let's check on the target class as well.
195195
Method specificMethod = AopUtils.getMostSpecificMethod(method, targetClass);
196-
return (specificMethod != method &&
196+
return (!specificMethod.equals(method) &&
197197
(AnnotationUtils.getAnnotation(specificMethod, this.annotationType) != null));
198198
}
199199

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ public void subscribe(Subscriber<? super Message<T>> subscriber) {
106106
.<Message<T>>create(sink ->
107107
sink.onRequest(n -> {
108108
Message<?> m;
109-
while (!sink.isCancelled() && n-- > 0 && (m = this.channel.receive()) != null) {
109+
while (!sink.isCancelled() && n-- > 0
110+
&& (m = this.channel.receive()) != null) { // NOSONAR
110111
sink.next((Message<T>) m);
111112
}
112113
}),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public final class FixedSubscriberChannelBeanFactoryPostProcessor implements Bea
3939

4040
private final Map<String, String> candidateFixedChannelHandlerMap;
4141

42-
private FixedSubscriberChannelBeanFactoryPostProcessor(Map<String, String> candidateHandlers) {
42+
FixedSubscriberChannelBeanFactoryPostProcessor(Map<String, String> candidateHandlers) {
4343
this.candidateFixedChannelHandlerMap = candidateHandlers;
4444
}
4545

spring-integration-core/src/main/java/org/springframework/integration/config/annotation/AbstractMethodAnnotationPostProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public Object postProcess(Object bean, String beanName, Method method, List<Anno
158158
orderable(method, handler);
159159
producerOrRouter(annotations, handler);
160160

161-
if (handler != sourceHandler) {
161+
if (!handler.equals(sourceHandler)) {
162162
String handlerBeanName = generateHandlerBeanName(beanName, method);
163163
if (handler instanceof ReplyProducingMessageHandlerWrapper
164164
&& StringUtils.hasText(MessagingAnnotationUtils.endpointIdValue(method))) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected BeanDefinitionBuilder buildBeanDefinition(Element element, ParserConte
5252

5353
// configure a queue-based channel if any queue sub-element is defined
5454
String channel = element.getAttribute(ID_ATTRIBUTE);
55-
if ((queueElement = DomUtils.getChildElementByTagName(element, "queue")) != null) {
55+
if ((queueElement = DomUtils.getChildElementByTagName(element, "queue")) != null) { // NOSONAR inner assignment
5656
builder = BeanDefinitionBuilder.genericBeanDefinition(QueueChannel.class);
5757
boolean hasStoreRef = this.parseStoreRef(builder, queueElement, channel, false);
5858
boolean hasQueueRef = this.parseQueueRef(builder, queueElement);
@@ -76,7 +76,7 @@ protected BeanDefinitionBuilder buildBeanDefinition(Element element, ParserConte
7676
element);
7777
}
7878
}
79-
else if ((queueElement = DomUtils.getChildElementByTagName(element, "priority-queue")) != null) {
79+
else if ((queueElement = DomUtils.getChildElementByTagName(element, "priority-queue")) != null) { // NOSONAR
8080
builder = BeanDefinitionBuilder.genericBeanDefinition(PriorityChannel.class);
8181
boolean hasCapacity = this.parseQueueCapacity(builder, queueElement);
8282
String comparatorRef = queueElement.getAttribute("comparator");
@@ -97,7 +97,7 @@ else if ((queueElement = DomUtils.getChildElementByTagName(element, "priority-qu
9797
}
9898

9999
}
100-
else if ((queueElement = DomUtils.getChildElementByTagName(element, "rendezvous-queue")) != null) {
100+
else if ((queueElement = DomUtils.getChildElementByTagName(element, "rendezvous-queue")) != null) { // NOSONAR
101101
builder = BeanDefinitionBuilder.genericBeanDefinition(RendezvousChannel.class);
102102
}
103103

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
*
3636
* @author Mark Fisher
3737
* @author Iwein Fuld
38+
* @author Gary Russell
3839
*/
3940
public class SelectorChainParser extends AbstractSingleBeanDefinitionParser {
4041

@@ -43,6 +44,7 @@ protected String getBeanClassName(Element element) {
4344
return MessageSelectorChain.class.getName();
4445
}
4546

47+
@Override
4648
public void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
4749
if (!StringUtils.hasText(element.getAttribute("id"))) {
4850
parserContext.getReaderContext().error("id is required", element);
@@ -82,8 +84,7 @@ private RuntimeBeanReference buildSelectorChain(ParserContext parserContext, Nod
8284
this.parseSelectorChain(nestedBuilder, (Element) child, parserContext);
8385
String nestedBeanName = BeanDefinitionReaderUtils.registerWithGeneratedName(nestedBuilder.getBeanDefinition(),
8486
parserContext.getRegistry());
85-
RuntimeBeanReference built = new RuntimeBeanReference(nestedBeanName);
86-
return built;
87+
return new RuntimeBeanReference(nestedBeanName);
8788
}
8889

8990
private RuntimeBeanReference buildMethodInvokingSelector(ParserContext parserContext, String ref, String method) {

spring-integration-core/src/main/java/org/springframework/integration/dsl/context/StandardIntegrationFlowContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public final class StandardIntegrationFlowContext implements IntegrationFlowCont
5959

6060
private BeanDefinitionRegistry beanDefinitionRegistry;
6161

62-
private StandardIntegrationFlowContext() {
62+
StandardIntegrationFlowContext() {
6363
}
6464

6565
@Override

spring-integration-core/src/main/java/org/springframework/integration/router/RecipientListRouter.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,15 @@ public void addRecipient(String channelName, String selectorExpression) {
137137
addRecipient(channelName, selectorExpression, this.recipients);
138138
}
139139

140-
private void addRecipient(String channelName, String selectorExpression, Queue<Recipient> recipients) {
140+
private void addRecipient(String channelName, String selectorExpression, Queue<Recipient> recipientsToAdd) {
141141
Assert.hasText(channelName, "'channelName' must not be empty.");
142142
Assert.hasText(selectorExpression, "'selectorExpression' must not be empty.");
143143
ExpressionEvaluatingSelector expressionEvaluatingSelector =
144144
new ExpressionEvaluatingSelector(selectorExpression);
145145
expressionEvaluatingSelector.setBeanFactory(getBeanFactory());
146146
Recipient recipient = new Recipient(channelName, expressionEvaluatingSelector);
147147
setupRecipient(recipient);
148-
recipients.add(recipient);
148+
recipientsToAdd.add(recipient);
149149
}
150150

151151
@Override
@@ -158,11 +158,11 @@ public void addRecipient(String channelName, MessageSelector selector) {
158158
addRecipient(channelName, selector, this.recipients);
159159
}
160160

161-
private void addRecipient(String channelName, MessageSelector selector, Queue<Recipient> recipients) {
161+
private void addRecipient(String channelName, MessageSelector selector, Queue<Recipient> recipientsToAdd) {
162162
Assert.hasText(channelName, "'channelName' must not be empty.");
163163
Recipient recipient = new Recipient(channelName, selector);
164164
setupRecipient(recipient);
165-
recipients.add(recipient);
165+
recipientsToAdd.add(recipient);
166166
}
167167

168168
public void addRecipient(MessageChannel channel) {
@@ -208,9 +208,9 @@ public int removeRecipient(String channelName, String selectorExpression) {
208208
Recipient next = it.next();
209209
MessageSelector selector = next.getSelector();
210210
MessageChannel channel = next.getChannel();
211-
if (selector instanceof ExpressionEvaluatingSelector &&
212-
channel == targetChannel &&
213-
((ExpressionEvaluatingSelector) selector).getExpressionString().equals(selectorExpression)) {
211+
if (selector instanceof ExpressionEvaluatingSelector
212+
&& channel.equals(targetChannel)
213+
&& ((ExpressionEvaluatingSelector) selector).getExpressionString().equals(selectorExpression)) {
214214
it.remove();
215215
counter++;
216216
}

0 commit comments

Comments
 (0)