Skip to content

Commit df62147

Browse files
committed
Fix new Sonar smells
1 parent 07a6fb3 commit df62147

File tree

20 files changed

+142
-173
lines changed

20 files changed

+142
-173
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ project('spring-integration-jpa') {
610610
}
611611
testImplementation "com.h2database:h2:$h2Version"
612612
testImplementation "org.hibernate:hibernate-entitymanager:$hibernateVersion"
613+
testImplementation "org.hamcrest:hamcrest-core:$hamcrestVersion"
613614
}
614615
}
615616

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2020 the original author or authors.
2+
* Copyright 2014-2021 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.
@@ -89,7 +89,7 @@ public boolean send(Message<?> message, long timeout) {
8989

9090
@Override
9191
public boolean subscribe(MessageHandler handler) {
92-
if (handler != this.handler && LOGGER.isDebugEnabled()) {
92+
if (!this.handler.equals(handler) && LOGGER.isDebugEnabled()) {
9393
LOGGER.debug(getComponentName() + ": cannot be subscribed to (it has a fixed single subscriber).");
9494
}
9595
return false;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ private PublisherAnnotationBeanPostProcessor createPublisherAnnotationBeanPostPr
103103
if (beanFactory != null) {
104104
order = beanFactory.resolveEmbeddedValue(order);
105105
}
106-
postProcessor.setOrder(Integer.parseInt(order));
106+
if (StringUtils.hasText(order)) {
107+
postProcessor.setOrder(Integer.parseInt(order));
108+
}
107109
}
108110
return postProcessor;
109111
}

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
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 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.
@@ -46,9 +46,9 @@ public class PointToPointChannelParser extends AbstractChannelParser {
4646
@Override
4747
protected BeanDefinitionBuilder buildBeanDefinition(Element element, ParserContext parserContext) {
4848
BeanDefinitionBuilder builder = null;
49-
Element queueElement = null;
49+
Element queueElement;
5050
String fixedSubscriberChannel = element.getAttribute("fixed-subscriber");
51-
boolean isFixedSubscriber = "true".equals(fixedSubscriberChannel.trim().toLowerCase());
51+
boolean isFixedSubscriber = "true".equalsIgnoreCase(fixedSubscriberChannel.trim());
5252

5353
// configure a queue-based channel if any queue sub-element is defined
5454
String channel = element.getAttribute(ID_ATTRIBUTE);

spring-integration-core/src/main/java/org/springframework/integration/mapping/AbstractHeaderMapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 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.
@@ -277,7 +277,7 @@ private void copyHeaders(Map<String, Object> source, Map<String, Object> target,
277277
if (shouldMapHeader(headerName, headerMatcher)) {
278278
Object value = entry.getValue();
279279
target.put(headerName, value);
280-
if (this.replyHeaderMatcher == headerMatcher &&
280+
if (this.replyHeaderMatcher.equals(headerMatcher) &&
281281
JsonHeaders.TYPE_ID.equals(headerName) && value != null) {
282282

283283
ResolvableType resolvableType =

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

Lines changed: 2 additions & 2 deletions
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-2021 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.
@@ -107,7 +107,7 @@ private int determineTypeDifferenceWeight(String candidate, Class<?> type, int l
107107
}
108108
// no match at this level, continue up the hierarchy
109109
for (Class<?> superInterface : iface.getInterfaces()) {
110-
int weight = this.determineTypeDifferenceWeight(candidate, superInterface, level + 3);
110+
int weight = this.determineTypeDifferenceWeight(candidate, superInterface, level + 3); // NOSONAR
111111
if (weight < Integer.MAX_VALUE) {
112112
return weight;
113113
}

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

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 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.router;
1818

19+
import java.util.ArrayList;
1920
import java.util.Collection;
2021
import java.util.Collections;
2122
import java.util.Iterator;
@@ -98,13 +99,8 @@ public void setChannels(List<MessageChannel> channels) {
9899
public void setRecipients(List<Recipient> recipients) {
99100
Assert.notEmpty(recipients, "'recipients' must not be empty");
100101
Queue<Recipient> newRecipients = new ConcurrentLinkedQueue<>(recipients);
101-
102102
newRecipients.forEach(this::setupRecipient);
103-
104-
if (logger.isDebugEnabled()) {
105-
logger.debug("Channel Recipients: " + this.recipients + " replaced with: " + newRecipients);
106-
}
107-
103+
logger.debug(() -> "Channel Recipients: " + this.recipients + " replaced with: " + newRecipients);
108104
this.recipients = newRecipients;
109105
}
110106

@@ -126,10 +122,7 @@ public void setRecipientMappings(Map<String, String> recipientMappings) {
126122
addRecipient(next.getKey(), (MessageSelector) null, newRecipients);
127123
}
128124
}
129-
if (logger.isDebugEnabled()) {
130-
logger.debug("Channel Recipients: " + this.recipients + " replaced with: " + newRecipients);
131-
}
132-
125+
logger.debug(() -> "Channel Recipients: " + this.recipients + " replaced with: " + newRecipients);
133126
this.recipients = newRecipients;
134127
}
135128

@@ -193,7 +186,7 @@ public int removeRecipient(String channelName) {
193186
int counter = 0;
194187
MessageChannel channel = getChannelResolver().resolveDestination(channelName);
195188
for (Iterator<Recipient> it = this.recipients.iterator(); it.hasNext(); ) {
196-
if (it.next().getChannel() == channel) {
189+
if (channel.equals(it.next().getChannel())) {
197190
it.remove();
198191
counter++;
199192
}
@@ -236,9 +229,7 @@ public void replaceRecipients(Properties recipientMappings) {
236229
addRecipient(key);
237230
}
238231
}
239-
if (logger.isDebugEnabled()) {
240-
logger.debug("Channel Recipients:" + originalRecipients + " replaced with:" + this.recipients);
241-
}
232+
logger.debug(() -> "Channel Recipients: " + originalRecipients + " replaced with: " + this.recipients);
242233
}
243234

244235
@Override
@@ -259,10 +250,13 @@ public IntegrationPatternType getIntegrationPatternType() {
259250

260251
@Override
261252
protected Collection<MessageChannel> determineTargetChannels(Message<?> message) {
262-
return this.recipients.stream()
263-
.filter(recipient -> recipient.accept(message))
264-
.map(Recipient::getChannel)
265-
.collect(Collectors.toList());
253+
List<MessageChannel> result = new ArrayList<>();
254+
for (Recipient recipient : this.recipients) {
255+
if (recipient.accept(message)) {
256+
result.add(recipient.getChannel());
257+
}
258+
}
259+
return result;
266260
}
267261

268262

spring-integration-core/src/main/java/org/springframework/integration/scheduling/PollerMetadata.java

Lines changed: 21 additions & 12 deletions
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-2021 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.
@@ -31,11 +31,23 @@
3131
* @author Mark Fisher
3232
* @author Oleg Zhurakousky
3333
* @author Gary Russell
34+
* @author Artem Bilan
3435
*/
3536
public class PollerMetadata {
3637

38+
/**
39+
* The constant for unlimited number of message to poll in one cycle.
40+
*/
3741
public static final int MAX_MESSAGES_UNBOUNDED = Integer.MIN_VALUE;
3842

43+
/**
44+
* The default receive timeout as one second.
45+
*/
46+
public static final long DEFAULT_RECEIVE_TIMEOUT = 1000;
47+
48+
/**
49+
* The bean name for global default poller.
50+
*/
3951
public static final String DEFAULT_POLLER_METADATA_BEAN_NAME =
4052
"org.springframework.integration.context.defaultPollerMetadata";
4153

@@ -44,21 +56,21 @@ public class PollerMetadata {
4456
*/
4557
public static final String DEFAULT_POLLER = DEFAULT_POLLER_METADATA_BEAN_NAME;
4658

47-
private volatile Trigger trigger;
59+
private Trigger trigger;
4860

49-
private volatile long maxMessagesPerPoll = MAX_MESSAGES_UNBOUNDED;
61+
private long maxMessagesPerPoll = MAX_MESSAGES_UNBOUNDED;
5062

51-
private volatile long receiveTimeout = 1000;
63+
private long receiveTimeout = DEFAULT_RECEIVE_TIMEOUT;
5264

53-
private volatile ErrorHandler errorHandler;
65+
private ErrorHandler errorHandler;
5466

55-
private volatile List<Advice> adviceChain;
67+
private List<Advice> adviceChain;
5668

57-
private volatile Executor taskExecutor;
69+
private Executor taskExecutor;
5870

59-
private volatile long sendTimeout;
71+
private long sendTimeout;
6072

61-
private volatile TransactionSynchronizationFactory transactionSynchronizationFactory;
73+
private TransactionSynchronizationFactory transactionSynchronizationFactory;
6274

6375

6476
public void setTransactionSynchronizationFactory(
@@ -91,11 +103,8 @@ public void setErrorHandler(ErrorHandler errorHandler) {
91103
* Set the maximum number of messages to receive for each poll.
92104
* A non-positive value indicates that polling should repeat as long
93105
* as non-null messages are being received and successfully sent.
94-
*
95106
* <p>The default is unbounded.
96-
*
97107
* @param maxMessagesPerPoll The maxMessagesPerPoll to set.
98-
*
99108
* @see #MAX_MESSAGES_UNBOUNDED
100109
*/
101110
public void setMaxMessagesPerPoll(long maxMessagesPerPoll) {

spring-integration-core/src/main/java/org/springframework/integration/support/json/Jackson2JsonObjectMapper.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,44 +198,46 @@ protected JavaType constructType(Type type) {
198198

199199
private void registerWellKnownModulesIfAvailable() {
200200
if (JDK8_MODULE_PRESENT) {
201-
this.objectMapper.registerModule(Jdk8ModuleProvider.module);
201+
this.objectMapper.registerModule(Jdk8ModuleProvider.MODULE);
202202
}
203203

204204
if (JAVA_TIME_MODULE_PRESENT) {
205-
this.objectMapper.registerModule(JavaTimeModuleProvider.module);
205+
this.objectMapper.registerModule(JavaTimeModuleProvider.MODULE);
206206
}
207207

208208
if (JODA_MODULE_PRESENT) {
209-
this.objectMapper.registerModule(JodaModuleProvider.module);
209+
this.objectMapper.registerModule(JodaModuleProvider.MODULE);
210210
}
211211

212212
if (KOTLIN_MODULE_PRESENT) {
213-
this.objectMapper.registerModule(KotlinModuleProvider.module);
213+
this.objectMapper.registerModule(KotlinModuleProvider.MODULE);
214214
}
215215
}
216216

217217
private static final class Jdk8ModuleProvider {
218218

219-
static final com.fasterxml.jackson.databind.Module module = new com.fasterxml.jackson.datatype.jdk8.Jdk8Module();
219+
static final com.fasterxml.jackson.databind.Module MODULE =
220+
new com.fasterxml.jackson.datatype.jdk8.Jdk8Module();
220221

221222
}
222223

223224
private static final class JavaTimeModuleProvider {
224225

225-
static final com.fasterxml.jackson.databind.Module module =
226+
static final com.fasterxml.jackson.databind.Module MODULE =
226227
new com.fasterxml.jackson.datatype.jsr310.JavaTimeModule();
227228

228229
}
229230

230231
private static final class JodaModuleProvider {
231232

232-
static final com.fasterxml.jackson.databind.Module module = new com.fasterxml.jackson.datatype.joda.JodaModule();
233+
static final com.fasterxml.jackson.databind.Module MODULE =
234+
new com.fasterxml.jackson.datatype.joda.JodaModule();
233235

234236
}
235237

236238
private static final class KotlinModuleProvider {
237239

238-
static final com.fasterxml.jackson.databind.Module module =
240+
static final com.fasterxml.jackson.databind.Module MODULE =
239241
new com.fasterxml.jackson.module.kotlin.KotlinModule();
240242

241243
}

0 commit comments

Comments
 (0)