Skip to content

Commit 6e11d4c

Browse files
committed
Fix new and some old Sonar smells
1 parent 9223613 commit 6e11d4c

27 files changed

+287
-305
lines changed

spring-integration-core/src/main/java/org/springframework/integration/filter/ExpressionEvaluatingSelector.java

Lines changed: 5 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-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.
@@ -30,17 +30,19 @@
3030
* @author Mark Fisher
3131
* @author Liujiong
3232
* @author Gary Russell
33+
* @author Artem Bilan
34+
*
3335
* @since 2.0
3436
*/
3537
public class ExpressionEvaluatingSelector extends AbstractMessageProcessingSelector {
3638

37-
private static final ExpressionParser expressionParser =
39+
private static final ExpressionParser EXPRESSION_PARSER =
3840
new SpelExpressionParser(new SpelParserConfiguration(true, true));
3941

4042
private final String expressionString;
4143

4244
public ExpressionEvaluatingSelector(String expressionString) {
43-
super(new ExpressionEvaluatingMessageProcessor<Boolean>(expressionParser.parseExpression(expressionString),
45+
super(new ExpressionEvaluatingMessageProcessor<Boolean>(EXPRESSION_PARSER.parseExpression(expressionString),
4446
Boolean.class));
4547
this.expressionString = expressionString;
4648
}

spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayMethodInboundMessageMapper.java

Lines changed: 5 additions & 6 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-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.
@@ -397,11 +397,10 @@ private void processHeadersAnnotation(Map<String, Object> headersToPopulate, @Nu
397397
private void processMapArgument(Object messageOrPayload, boolean foundPayloadAnnotation,
398398
Map<String, Object> headersToPopulate, Map<?, ?> argumentValue) {
399399

400-
if (messageOrPayload instanceof Map && !foundPayloadAnnotation) {
401-
if (GatewayMethodInboundMessageMapper.this.payloadExpression == null) {
402-
throw new MessagingException("Ambiguous method parameters; found more than one " +
403-
"Map-typed parameter and neither one contains a @Payload annotation");
404-
}
400+
if (messageOrPayload instanceof Map && !foundPayloadAnnotation
401+
&& GatewayMethodInboundMessageMapper.this.payloadExpression == null) {
402+
throw new MessagingException("Ambiguous method parameters; found more than one " +
403+
"Map-typed parameter and neither one contains a @Payload annotation");
405404
}
406405
copyHeaders(argumentValue, headersToPopulate);
407406
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2019 the original author or authors.
2+
* Copyright 2017-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.
@@ -41,7 +41,7 @@
4141
*/
4242
public final class SimpleJsonSerializer {
4343

44-
private static final Log logger = LogFactory.getLog(SimpleJsonSerializer.class);
44+
private static final Log LOGGER = LogFactory.getLog(SimpleJsonSerializer.class);
4545

4646
private SimpleJsonSerializer() {
4747
}
@@ -69,12 +69,12 @@ public static String toJson(Object bean, String... propertiesToExclude) {
6969
}
7070
catch (InvocationTargetException | IllegalAccessException | IllegalArgumentException e) {
7171
Throwable exception = e;
72-
if (e instanceof InvocationTargetException) {
72+
if (e instanceof InvocationTargetException) { // NOSONAR
7373
exception = e.getCause();
7474
}
7575

76-
if (logger.isDebugEnabled()) {
77-
logger.debug("Failed to serialize property " + propertyName, exception);
76+
if (LOGGER.isDebugEnabled()) {
77+
LOGGER.debug("Failed to serialize property " + propertyName, exception);
7878
}
7979

8080
result =

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
@@ -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.
@@ -35,6 +35,7 @@
3535
import org.springframework.integration.filter.ExpressionEvaluatingSelector;
3636
import org.springframework.jmx.export.annotation.ManagedAttribute;
3737
import org.springframework.jmx.export.annotation.ManagedOperation;
38+
import org.springframework.lang.Nullable;
3839
import org.springframework.messaging.Message;
3940
import org.springframework.messaging.MessageChannel;
4041
import org.springframework.messaging.core.DestinationResolver;
@@ -210,7 +211,7 @@ public int removeRecipient(String channelName, String selectorExpression) {
210211
MessageSelector selector = next.getSelector();
211212
MessageChannel channel = next.getChannel();
212213
if (selector instanceof ExpressionEvaluatingSelector
213-
&& channel.equals(targetChannel)
214+
&& targetChannel.equals(channel)
214215
&& ((ExpressionEvaluatingSelector) selector).getExpressionString().equals(selectorExpression)) {
215216
it.remove();
216217
counter++;
@@ -307,14 +308,13 @@ private MessageSelector getSelector() {
307308
return this.selector;
308309
}
309310

311+
@Nullable
310312
public MessageChannel getChannel() {
311313
if (this.channel == null) {
312314
String channelNameForInitialization = this.channelName;
313-
if (channelNameForInitialization != null) {
314-
if (this.channelResolver != null) {
315-
this.channel = this.channelResolver.resolveDestination(channelNameForInitialization);
316-
this.channelName = null;
317-
}
315+
if (channelNameForInitialization != null && this.channelResolver != null) {
316+
this.channel = this.channelResolver.resolveDestination(channelNameForInitialization);
317+
this.channelName = null;
318318
}
319319
}
320320
return this.channel;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-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.
@@ -34,7 +34,7 @@
3434
*/
3535
public class PollSkipAdvice implements MethodInterceptor {
3636

37-
private static final Log logger = LogFactory.getLog(PollSkipAdvice.class);
37+
private static final Log LOGGER = LogFactory.getLog(PollSkipAdvice.class);
3838

3939
private final PollSkipStrategy pollSkipStrategy;
4040

@@ -51,8 +51,8 @@ public PollSkipAdvice(PollSkipStrategy strategy) {
5151
@Override
5252
public Object invoke(MethodInvocation invocation) throws Throwable {
5353
if ("call".equals(invocation.getMethod().getName()) && this.pollSkipStrategy.skipPoll()) {
54-
if (logger.isDebugEnabled()) {
55-
logger.debug("Skipping poll because "
54+
if (LOGGER.isDebugEnabled()) {
55+
LOGGER.debug("Skipping poll because "
5656
+ this.pollSkipStrategy.getClass().getName()
5757
+ ".skipPoll() returned true");
5858
}

spring-integration-core/src/main/java/org/springframework/integration/store/PersistentMessageGroup.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2019 the original author or authors.
2+
* Copyright 2016-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.
@@ -33,7 +33,7 @@
3333
*/
3434
class PersistentMessageGroup implements MessageGroup {
3535

36-
private static final Log logger = LogFactory.getLog(PersistentMessageGroup.class);
36+
private static final Log LOGGER = LogFactory.getLog(PersistentMessageGroup.class);
3737

3838
private final MessageGroupStore messageGroupStore;
3939

@@ -64,8 +64,8 @@ public Message<?> getOne() {
6464
if (this.oneMessage == null) {
6565
synchronized (this) {
6666
if (this.oneMessage == null) {
67-
if (logger.isDebugEnabled()) {
68-
logger.debug("Lazy loading of one message for messageGroup: " + this.original.getGroupId());
67+
if (LOGGER.isDebugEnabled()) {
68+
LOGGER.debug("Lazy loading of one message for messageGroup: " + this.original.getGroupId());
6969
}
7070
this.oneMessage = this.messageGroupStore.getOneMessageFromGroup(this.original.getGroupId());
7171
}
@@ -97,8 +97,8 @@ public int size() {
9797
if (this.size == 0) {
9898
synchronized (this) {
9999
if (this.size == 0) {
100-
if (logger.isDebugEnabled()) {
101-
logger.debug("Lazy loading of group size for messageGroup: " + this.original.getGroupId());
100+
if (LOGGER.isDebugEnabled()) {
101+
LOGGER.debug("Lazy loading of group size for messageGroup: " + this.original.getGroupId());
102102
}
103103
this.size = this.messageGroupStore.messageGroupSize(this.original.getGroupId());
104104
}
@@ -180,8 +180,8 @@ private void load() {
180180
synchronized (this) {
181181
if (this.collection == null) {
182182
Object groupId = PersistentMessageGroup.this.original.getGroupId();
183-
if (logger.isDebugEnabled()) {
184-
logger.debug("Lazy loading of messages for messageGroup: " + groupId);
183+
if (LOGGER.isDebugEnabled()) {
184+
LOGGER.debug("Lazy loading of messages for messageGroup: " + groupId);
185185
}
186186
this.collection = PersistentMessageGroup.this.messageGroupStore.getMessagesForGroup(groupId);
187187
}

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

Lines changed: 4 additions & 4 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-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.
@@ -41,11 +41,11 @@
4141
* @author Gary Russell
4242
* @author Artem Bilan
4343
*
44-
* @see org.springframework.beans.factory.BeanFactory
44+
* @see BeanFactory
4545
*/
4646
public class BeanFactoryChannelResolver implements DestinationResolver<MessageChannel>, BeanFactoryAware {
4747

48-
private static final Log logger = LogFactory.getLog(BeanFactoryChannelResolver.class);
48+
private static final Log LOGGER = LogFactory.getLog(BeanFactoryChannelResolver.class);
4949

5050
private BeanFactory beanFactory;
5151

@@ -102,7 +102,7 @@ public MessageChannel resolveDestination(String name) {
102102
HeaderChannelRegistry.class);
103103
}
104104
catch (Exception ex) {
105-
logger.debug("No HeaderChannelRegistry found");
105+
LOGGER.debug("No HeaderChannelRegistry found");
106106
}
107107
this.initialized = true;
108108
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2019 the original author or authors.
2+
* Copyright 2013-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.
@@ -43,7 +43,7 @@
4343
*/
4444
public abstract class AbstractJacksonJsonObjectMapper<N, P, J> implements JsonObjectMapper<N, P>, BeanClassLoaderAware {
4545

46-
protected static final Collection<Class<?>> supportedJsonTypes =
46+
protected static final Collection<Class<?>> SUPPORTED_JSON_TYPES =
4747
Arrays.asList(String.class, byte[].class, File.class, URL.class, InputStream.class, Reader.class);
4848

4949
private volatile ClassLoader classLoader = ClassUtils.getDefaultClassLoader();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2019 the original author or authors.
2+
* Copyright 2013-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.
@@ -150,7 +150,7 @@ else if (json instanceof Reader) {
150150
return this.objectMapper.readValue((Reader) json, type);
151151
}
152152
else {
153-
throw new IllegalArgumentException("'json' argument must be an instance of: " + supportedJsonTypes
153+
throw new IllegalArgumentException("'json' argument must be an instance of: " + SUPPORTED_JSON_TYPES
154154
+ " , but gotten: " + json.getClass());
155155
}
156156
}

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,14 @@ public final class JacksonPresent {
2929

3030
private static final ClassLoader CLASS_LOADER = ClassUtils.getDefaultClassLoader();
3131

32-
private static final boolean jackson2Present =
32+
private static final boolean JACKSON_2_PRESENT =
3333
ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", CLASS_LOADER) &&
3434
ClassUtils.isPresent("com.fasterxml.jackson.core.JsonGenerator", CLASS_LOADER);
3535

36-
private static final boolean jacksonPresent =
37-
ClassUtils.isPresent("org.codehaus.jackson.map.ObjectMapper", CLASS_LOADER) &&
38-
ClassUtils.isPresent("org.codehaus.jackson.JsonGenerator", CLASS_LOADER);
39-
4036
public static boolean isJackson2Present() {
41-
return jackson2Present;
42-
}
43-
44-
/**
45-
* @return true if Jackson 1.x is present on classpath
46-
* @deprecated Jackson 1.x is not supported any more. Use Jackson 2.x.
47-
*/
48-
@Deprecated
49-
public static boolean isJacksonPresent() {
50-
return jacksonPresent;
37+
return JACKSON_2_PRESENT;
5138
}
5239

53-
5440
private JacksonPresent() {
5541
}
5642

0 commit comments

Comments
 (0)