Skip to content

Commit 1bafe89

Browse files
garyrussellartembilan
authored andcommitted
Sonar Fixes
- avoid parameter assignments
1 parent 76439e3 commit 1bafe89

File tree

29 files changed

+236
-163
lines changed

29 files changed

+236
-163
lines changed

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

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -407,16 +407,17 @@ public boolean send(Message<?> message) {
407407
* is interrupted. If the specified timeout is 0, the method will return
408408
* immediately. If less than zero, it will block indefinitely (see
409409
* {@link #send(Message)}).
410-
* @param message the Message to send
410+
* @param messageArg the Message to send
411411
* @param timeout the timeout in milliseconds
412412
* @return <code>true</code> if the message is sent successfully,
413413
* <code>false</code> if the message cannot be sent within the allotted
414414
* time or the sending thread is interrupted.
415415
*/
416416
@Override
417-
public boolean send(Message<?> message, long timeout) {
418-
Assert.notNull(message, "message must not be null");
419-
Assert.notNull(message.getPayload(), "message payload must not be null");
417+
public boolean send(Message<?> messageArg, long timeout) {
418+
Assert.notNull(messageArg, "message must not be null");
419+
Assert.notNull(messageArg.getPayload(), "message payload must not be null");
420+
Message<?> message = messageArg;
420421
if (this.shouldTrack) {
421422
message = MessageHistory.write(message, this, this.getMessageBuilderFactory());
422423
}
@@ -596,8 +597,10 @@ public void add(int index, ChannelInterceptor interceptor) {
596597
}
597598

598599
@Nullable
599-
public Message<?> preSend(Message<?> message, MessageChannel channel,
600+
public Message<?> preSend(Message<?> messageArg, MessageChannel channel,
600601
Deque<ChannelInterceptor> interceptorStack) {
602+
603+
Message<?> message = messageArg;
601604
if (this.size > 0) {
602605
for (ChannelInterceptor interceptor : this.interceptors) {
603606
Message<?> previous = message;
@@ -652,7 +655,8 @@ public boolean preReceive(MessageChannel channel, Deque<ChannelInterceptor> inte
652655
}
653656

654657
@Nullable
655-
public Message<?> postReceive(Message<?> message, MessageChannel channel) {
658+
public Message<?> postReceive(Message<?> messageArg, MessageChannel channel) {
659+
Message<?> message = messageArg;
656660
if (this.size > 0) {
657661
for (ChannelInterceptor interceptor : this.interceptors) {
658662
message = interceptor.postReceive(message, channel);

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -124,9 +124,11 @@ protected boolean doSend(Message<?> message, long timeout) {
124124
return false;
125125
}
126126
if (!this.useMessageStore) {
127-
message = new MessageWrapper(message);
127+
return super.doSend(new MessageWrapper(message), 0);
128+
}
129+
else {
130+
return super.doSend(message, 0);
128131
}
129-
return super.doSend(message, 0);
130132
}
131133

132134
@Override

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2018 the original author or authors.
2+
* Copyright 2014-2019 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.
@@ -100,8 +100,10 @@ public Object postProcess(Object bean, String beanName, Method method, List<Anno
100100
return adapter;
101101
}
102102

103-
private MessageSource<?> createMessageSource(Object bean, String beanName, Method method) {
103+
private MessageSource<?> createMessageSource(Object beanArg, String beanName, Method methodArg) {
104104
MessageSource<?> messageSource = null;
105+
Object bean = beanArg;
106+
Method method = methodArg;
105107
if (AnnotatedElementUtils.isAnnotated(method, Bean.class.getName())) {
106108
Object target = this.resolveTargetBeanFromMethodWithBeanAnnotation(method);
107109
Class<?> targetClass = target.getClass();

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -36,6 +36,7 @@
3636
* @author Mark Fisher
3737
* @author Dave Syer
3838
* @author Artem Bilan
39+
* @author Gary Russell
3940
*/
4041
public abstract class AbstractChannelParser extends AbstractBeanDefinitionParser {
4142

@@ -86,10 +87,13 @@ protected AbstractBeanDefinition parseInternal(Element element, ParserContext pa
8687
@Override
8788
protected void registerBeanDefinition(BeanDefinitionHolder definition, BeanDefinitionRegistry registry) {
8889
String scope = definition.getBeanDefinition().getScope();
89-
if (!AbstractBeanDefinition.SCOPE_DEFAULT.equals(scope) && !AbstractBeanDefinition.SCOPE_SINGLETON.equals(scope) && !AbstractBeanDefinition.SCOPE_PROTOTYPE.equals(scope)) {
90-
definition = ScopedProxyUtils.createScopedProxy(definition, registry, false);
90+
if (!AbstractBeanDefinition.SCOPE_DEFAULT.equals(scope) && !AbstractBeanDefinition.SCOPE_SINGLETON.equals(scope)
91+
&& !AbstractBeanDefinition.SCOPE_PROTOTYPE.equals(scope)) {
92+
super.registerBeanDefinition(ScopedProxyUtils.createScopedProxy(definition, registry, false), registry);
93+
}
94+
else {
95+
super.registerBeanDefinition(definition, registry);
9196
}
92-
super.registerBeanDefinition(definition, registry);
9397
}
9498

9599
/**

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -39,6 +39,7 @@
3939
import org.springframework.integration.transformer.support.MessageProcessingHeaderValueMessageProcessor;
4040
import org.springframework.integration.transformer.support.RoutingSlipHeaderValueMessageProcessor;
4141
import org.springframework.integration.transformer.support.StaticHeaderValueMessageProcessor;
42+
import org.springframework.lang.Nullable;
4243
import org.springframework.util.StringUtils;
4344
import org.springframework.util.xml.DomUtils;
4445

@@ -148,11 +149,13 @@ protected void processHeaders(Element element, ManagedMap<String, Object> header
148149
}
149150

150151
private void addHeader(Element element, ManagedMap<String, Object> headers, ParserContext parserContext,
151-
String headerName, Element headerElement, String headerType, String expression, String overwrite) {
152+
String headerName, Element headerElement, String headerType, @Nullable String expressionArg,
153+
String overwrite) {
152154

153155
String value = headerElement.getAttribute("value");
154156
String ref = headerElement.getAttribute(REF_ATTRIBUTE);
155157
String method = headerElement.getAttribute(METHOD_ATTRIBUTE);
158+
String expression = expressionArg;
156159
if (expression == null) {
157160
expression = headerElement.getAttribute(EXPRESSION_ATTRIBUTE);
158161
}

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -47,6 +47,7 @@
4747
import org.springframework.integration.config.IntegrationConfigUtils;
4848
import org.springframework.integration.context.IntegrationContextUtils;
4949
import org.springframework.integration.transaction.TransactionHandleMessageAdvice;
50+
import org.springframework.lang.Nullable;
5051
import org.springframework.transaction.interceptor.DefaultTransactionAttribute;
5152
import org.springframework.transaction.interceptor.MatchAlwaysTransactionAttributeSource;
5253
import org.springframework.transaction.interceptor.TransactionInterceptor;
@@ -356,12 +357,14 @@ public static void configureHeaderMapper(Element element, BeanDefinitionBuilder
356357
* @param rootBuilder The root builder.
357358
* @param parserContext The parser context.
358359
* @param headerMapperBuilder The header mapper builder.
359-
* @param replyHeaderValue The reply header value.
360+
* @param replyHeaderValueArg The reply header value.
360361
*/
361362
public static void configureHeaderMapper(Element element, BeanDefinitionBuilder rootBuilder,
362-
ParserContext parserContext, BeanDefinitionBuilder headerMapperBuilder, String replyHeaderValue) {
363+
ParserContext parserContext, BeanDefinitionBuilder headerMapperBuilder,
364+
@Nullable String replyHeaderValueArg) {
363365

364366
String defaultMappedReplyHeadersAttributeName = "mapped-reply-headers";
367+
String replyHeaderValue = replyHeaderValueArg;
365368
if (!StringUtils.hasText(replyHeaderValue)) {
366369
replyHeaderValue = defaultMappedReplyHeadersAttributeName;
367370
}

spring-integration-core/src/main/java/org/springframework/integration/dispatcher/AggregateMessageDeliveryException.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -29,6 +29,7 @@
2929
*
3030
* @author Mark Fisher
3131
* @author Artem Bilan
32+
* @author Gary Russell
3233
*
3334
* @since 1.0.3
3435
*/
@@ -67,12 +68,14 @@ public String getMessage() {
6768

6869
private String appendPeriodIfNecessary(String baseMessage) {
6970
if (!StringUtils.hasText(baseMessage)) {
70-
baseMessage = "";
71+
return "";
7172
}
7273
else if (!baseMessage.endsWith(".")) {
73-
baseMessage = baseMessage + ".";
74+
return baseMessage + ".";
75+
}
76+
else {
77+
return baseMessage;
7478
}
75-
return baseMessage;
7679
}
7780

7881
}

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

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2018 the original author or authors.
2+
* Copyright 2016-2019 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.
@@ -221,13 +221,16 @@ public static IntegrationFlowBuilder from(MessageSource<?> messageSource) {
221221
* @see SourcePollingChannelAdapterSpec
222222
*/
223223
public static IntegrationFlowBuilder from(MessageSource<?> messageSource,
224-
Consumer<SourcePollingChannelAdapterSpec> endpointConfigurer) {
224+
@Nullable Consumer<SourcePollingChannelAdapterSpec> endpointConfigurer) {
225+
225226
return from(messageSource, endpointConfigurer, null);
226227
}
227228

228229
private static IntegrationFlowBuilder from(MessageSource<?> messageSource,
229-
Consumer<SourcePollingChannelAdapterSpec> endpointConfigurer,
230-
IntegrationFlowBuilder integrationFlowBuilder) {
230+
@Nullable Consumer<SourcePollingChannelAdapterSpec> endpointConfigurer,
231+
@Nullable IntegrationFlowBuilder integrationFlowBuilderArg) {
232+
233+
IntegrationFlowBuilder integrationFlowBuilder = integrationFlowBuilderArg;
231234
SourcePollingChannelAdapterSpec spec = new SourcePollingChannelAdapterSpec(messageSource);
232235
if (endpointConfigurer != null) {
233236
endpointConfigurer.accept(spec);
@@ -262,7 +265,9 @@ public static IntegrationFlowBuilder from(MessageProducerSupport messageProducer
262265
}
263266

264267
private static IntegrationFlowBuilder from(MessageProducerSupport messageProducer,
265-
IntegrationFlowBuilder integrationFlowBuilder) {
268+
@Nullable IntegrationFlowBuilder integrationFlowBuilderArg) {
269+
270+
IntegrationFlowBuilder integrationFlowBuilder = integrationFlowBuilderArg;
266271
MessageChannel outputChannel = messageProducer.getOutputChannel();
267272
if (outputChannel == null) {
268273
outputChannel = new DirectChannel();
@@ -354,8 +359,9 @@ public static IntegrationFlowBuilder from(Publisher<Message<?>> publisher) {
354359
}
355360

356361
private static IntegrationFlowBuilder from(MessagingGatewaySupport inboundGateway,
357-
IntegrationFlowBuilder integrationFlowBuilder) {
362+
@Nullable IntegrationFlowBuilder integrationFlowBuilderArg) {
358363

364+
IntegrationFlowBuilder integrationFlowBuilder = integrationFlowBuilderArg;
359365
MessageChannel outputChannel = inboundGateway.getRequestChannel();
360366
if (outputChannel == null) {
361367
outputChannel = new DirectChannel();

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2018 the original author or authors.
2+
* Copyright 2016-2019 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,6 +34,7 @@
3434
import org.springframework.integration.core.MessagingTemplate;
3535
import org.springframework.integration.dsl.IntegrationFlow;
3636
import org.springframework.integration.support.context.NamedComponent;
37+
import org.springframework.lang.Nullable;
3738
import org.springframework.util.Assert;
3839
import org.springframework.util.StringUtils;
3940

@@ -124,7 +125,8 @@ else if (this.registry.containsKey(flowId)) {
124125
}
125126

126127
@SuppressWarnings("unchecked")
127-
private Object registerBean(Object bean, String beanName, String parentName) {
128+
private Object registerBean(Object bean, @Nullable String beanNameArg, String parentName) {
129+
String beanName = beanNameArg;
128130
if (beanName == null) {
129131
beanName = generateBeanName(bean, parentName);
130132
}

spring-integration-core/src/main/java/org/springframework/integration/endpoint/MessageProducerSupport.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -192,7 +192,8 @@ protected void doStart() {
192192
protected void doStop() {
193193
}
194194

195-
protected void sendMessage(Message<?> message) {
195+
protected void sendMessage(Message<?> messageArg) {
196+
Message<?> message = messageArg;
196197
if (message == null) {
197198
throw new MessagingException("cannot send a null message");
198199
}

spring-integration-core/src/main/java/org/springframework/integration/endpoint/SourcePollingChannelAdapter.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -228,7 +228,8 @@ public MessageChannel getOutputChannel() {
228228
}
229229

230230
@Override
231-
protected void handleMessage(Message<?> message) {
231+
protected void handleMessage(Message<?> messageArg) {
232+
Message<?> message = messageArg;
232233
if (this.shouldTrack) {
233234
message = MessageHistory.write(message, this, getMessageBuilderFactory());
234235
}

spring-integration-core/src/main/java/org/springframework/integration/expression/ReloadableResourceBundleExpressionSource.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -408,9 +408,10 @@ private PropertiesHolder getProperties(String filename) {
408408
* The holder can be <code>null</code> if not cached before, or a timed-out cache entry
409409
* (potentially getting re-validated against the current last-modified timestamp).
410410
* @param filename the bundle filename (basename + Locale)
411-
* @param propHolder the current PropertiesHolder for the bundle
411+
* @param propHolderArg the current PropertiesHolder for the bundle
412412
*/
413-
private PropertiesHolder refreshProperties(String filename, PropertiesHolder propHolder) {
413+
private PropertiesHolder refreshProperties(String filename, @Nullable PropertiesHolder propHolderArg) {
414+
PropertiesHolder propHolder = propHolderArg;
414415
long refreshTimestamp = (this.cacheMillis < 0) ? -1 : System.currentTimeMillis();
415416

416417
Resource resource = this.resourceLoader.getResource(filename + PROPERTIES_SUFFIX);

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

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -232,10 +232,9 @@ public void setReplyTimeout(long replyTimeout) {
232232
* from any object passed in a send or sendAndReceive operation.
233233
* @param requestMapper The request mapper.
234234
*/
235-
public void setRequestMapper(InboundMessageMapper<?> requestMapper) {
236-
requestMapper = (requestMapper != null) ? requestMapper : new DefaultRequestMapper();
237-
this.requestMapper = requestMapper;
238-
this.messageConverter.setInboundMessageMapper(requestMapper);
235+
public void setRequestMapper(@Nullable InboundMessageMapper<?> requestMapper) {
236+
this.requestMapper = (requestMapper != null) ? requestMapper : new DefaultRequestMapper();
237+
this.messageConverter.setInboundMessageMapper(this.requestMapper);
239238
}
240239

241240
/**

spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractMessageHandler.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -139,7 +139,8 @@ protected void onInit() {
139139
}
140140

141141
@Override
142-
public void handleMessage(Message<?> message) {
142+
public void handleMessage(Message<?> messageArg) {
143+
Message<?> message = messageArg;
143144
Assert.notNull(message, "Message must not be null");
144145
Assert.notNull(message.getPayload(), "Message payload must not be null"); //NOSONAR - false positive
145146
if (this.loggingEnabled && this.logger.isDebugEnabled()) {

0 commit comments

Comments
 (0)