Skip to content

Commit 2cde493

Browse files
garyrussellartembilan
authored andcommitted
Sonar Fixes
Packages `o.s.i.g*` * Polishing - PR comments
1 parent 687e6d5 commit 2cde493

File tree

6 files changed

+42
-16
lines changed

6 files changed

+42
-16
lines changed

spring-integration-amqp/src/main/java/org/springframework/integration/amqp/inbound/AmqpInboundGateway.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.springframework.integration.gateway.MessagingGatewaySupport;
4242
import org.springframework.integration.support.ErrorMessageStrategy;
4343
import org.springframework.integration.support.ErrorMessageUtils;
44+
import org.springframework.messaging.MessageChannel;
4445
import org.springframework.retry.RecoveryCallback;
4546
import org.springframework.retry.support.RetrySynchronizationManager;
4647
import org.springframework.retry.support.RetryTemplate;
@@ -292,10 +293,11 @@ private org.springframework.messaging.Message<Object> convert(Message message, C
292293
}
293294
}
294295
catch (RuntimeException e) {
295-
if (getErrorChannel() != null) {
296+
MessageChannel errorChannel = getErrorChannel();
297+
if (errorChannel != null) {
296298
setAttributesIfNecessary(message, null);
297-
AmqpInboundGateway.this.messagingTemplate.send(getErrorChannel(), buildErrorMessage(null,
298-
new ListenerExecutionFailedException("Message conversion failed", e, message)));
299+
AmqpInboundGateway.this.messagingTemplate.send(errorChannel, buildErrorMessage(null,
300+
new ListenerExecutionFailedException("Message conversion failed", e, message)));
299301
}
300302
else {
301303
throw e;

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -188,6 +188,7 @@ public Message<?> toMessage(Object[] arguments, @Nullable Map<String, Object> he
188188
return mapArgumentsToMessage(arguments, headers);
189189
}
190190

191+
@Nullable
191192
private Message<?> mapArgumentsToMessage(Object[] arguments, Map<String, Object> headers) {
192193
try {
193194
return this.argsMapper.toMessage(new MethodArgsHolder(this.method, arguments), headers);
@@ -220,6 +221,7 @@ private StandardEvaluationContext createMethodInvocationEvaluationContext(Object
220221
return context;
221222
}
222223

224+
@Nullable
223225
private Object evaluatePayloadExpression(String expressionString, Object argumentValue) {
224226
Expression expression =
225227
this.parameterPayloadExpressions.computeIfAbsent(expressionString, PARSER::parseExpression);
@@ -317,7 +319,8 @@ public Message<?> toMessage(MethodArgsHolder holder, @Nullable Map<String, Objec
317319
}
318320
else if (annotation.annotationType().equals(Header.class)) {
319321
String headerName = determineHeaderName(annotation, methodParameter);
320-
if ((Boolean) AnnotationUtils.getValue(annotation, "required") && argumentValue == null) {
322+
if ((Boolean) AnnotationUtils.getValue(annotation, "required") // NOSONAR never null
323+
&& argumentValue == null) {
321324
throw new IllegalArgumentException("Received null argument value for required header: '"
322325
+ headerName + "'");
323326
}

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ public boolean isSingleton() {
434434
}
435435

436436
@Override
437+
@Nullable
437438
public Object invoke(final MethodInvocation invocation) throws Throwable {
438439
final Class<?> returnType = invocation.getMethod().getReturnType();
439440
if (this.asyncExecutor != null && !Object.class.equals(returnType)) {
@@ -458,16 +459,17 @@ else if (Future.class.isAssignableFrom(returnType)) {
458459
if (Mono.class.isAssignableFrom(returnType)) {
459460
return Mono.fromSupplier(new Invoker(invocation));
460461
}
461-
return this.doInvoke(invocation, true);
462+
return doInvoke(invocation, true);
462463
}
463464

465+
@Nullable
464466
protected Object doInvoke(MethodInvocation invocation, boolean runningOnCallerThread) throws Throwable {
465467
Method method = invocation.getMethod();
466468
if (AopUtils.isToStringMethod(method)) {
467469
return "gateway proxy for service interface [" + this.serviceInterface + "]";
468470
}
469471
try {
470-
return this.invokeGatewayMethod(invocation, runningOnCallerThread);
472+
return invokeGatewayMethod(invocation, runningOnCallerThread);
471473
}
472474
catch (Throwable e) { //NOSONAR - ok to catch, rethrown below
473475
this.rethrowExceptionCauseIfPossible(e, invocation.getMethod());
@@ -709,7 +711,10 @@ else if (StringUtils.hasText(this.defaultReplyChannelName)) {
709711
gateway.setRequestTimeout(-1);
710712
}
711713
else if (requestTimeout instanceof ValueExpression) {
712-
gateway.setRequestTimeout(requestTimeout.getValue(Long.class));
714+
Long timeout = requestTimeout.getValue(Long.class);
715+
if (timeout != null) {
716+
gateway.setRequestTimeout(timeout);
717+
}
713718
}
714719
else {
715720
messageMapper.setSendTimeoutExpression(requestTimeout);
@@ -718,7 +723,10 @@ else if (requestTimeout instanceof ValueExpression) {
718723
gateway.setReplyTimeout(-1);
719724
}
720725
else if (replyTimeout instanceof ValueExpression) {
721-
gateway.setReplyTimeout(replyTimeout.getValue(Long.class));
726+
Long timeout = replyTimeout.getValue(Long.class);
727+
if (timeout != null) {
728+
gateway.setReplyTimeout(timeout);
729+
}
722730
}
723731
else {
724732
messageMapper.setReplyTimeoutExpression(replyTimeout);
@@ -751,6 +759,7 @@ protected void doStop() {
751759
}
752760

753761
@SuppressWarnings("unchecked")
762+
@Nullable
754763
private <T> T convert(Object source, Class<T> expectedReturnType) {
755764
if (Future.class.isAssignableFrom(expectedReturnType)) {
756765
return (T) source;

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ public MessageChannel getReplyChannel() {
396396
* @return the channel or null.
397397
* @since 4.3
398398
*/
399+
@Nullable
399400
public MessageChannel getErrorChannel() {
400401
if (this.errorChannelName != null) {
401402
synchronized (this) {
@@ -431,6 +432,7 @@ protected void send(Object object) {
431432
}
432433
}
433434

435+
@Nullable
434436
protected Object receive() {
435437
this.initializeIfNecessary();
436438
MessageChannel replyChannel = getReplyChannel();
@@ -439,6 +441,7 @@ protected Object receive() {
439441
return this.messagingTemplate.receiveAndConvert(replyChannel, Object.class);
440442
}
441443

444+
@Nullable
442445
protected Message<?> receiveMessage() {
443446
initializeIfNecessary();
444447
MessageChannel replyChannel = getReplyChannel();
@@ -447,6 +450,7 @@ protected Message<?> receiveMessage() {
447450
return this.messagingTemplate.receive(replyChannel);
448451
}
449452

453+
@Nullable
450454
protected Object receive(long timeout) {
451455
this.initializeIfNecessary();
452456
MessageChannel replyChannel = getReplyChannel();
@@ -455,6 +459,7 @@ protected Object receive(long timeout) {
455459
return this.messagingTemplate.receiveAndConvert(replyChannel, timeout);
456460
}
457461

462+
@Nullable
458463
protected Message<?> receiveMessage(long timeout) {
459464
initializeIfNecessary();
460465
MessageChannel replyChannel = getReplyChannel();
@@ -463,10 +468,12 @@ protected Message<?> receiveMessage(long timeout) {
463468
return this.messagingTemplate.receive(replyChannel, timeout);
464469
}
465470

471+
@Nullable
466472
protected Object sendAndReceive(Object object) {
467473
return this.doSendAndReceive(object, true);
468474
}
469475

476+
@Nullable
470477
protected Message<?> sendAndReceiveMessage(Object object) {
471478
return (Message<?>) this.doSendAndReceive(object, false);
472479
}
@@ -716,7 +723,7 @@ protected final ErrorMessage buildErrorMessage(@Nullable Message<?> requestMessa
716723
* @return the attributes.
717724
* @since 4.3.10
718725
*/
719-
protected AttributeAccessor getErrorMessageAttributes(Message<?> message) {
726+
protected AttributeAccessor getErrorMessageAttributes(@Nullable Message<?> message) {
720727
return ErrorMessageUtils.getAttributeAccessor(message, null);
721728
}
722729

spring-integration-core/src/main/java/org/springframework/integration/graph/IntegrationGraphServer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,10 @@ private MessageChannelNode channelNode(String name, MessageChannel channel) {
351351
}
352352

353353
private MessageGatewayNode gatewayNode(String name, MessagingGatewaySupport gateway) {
354-
String errorChannel = gateway.getErrorChannel() != null ? gateway.getErrorChannel().toString() : null;
355-
String requestChannel = gateway.getRequestChannel() != null
356-
? gateway.getRequestChannel().toString() // NOSONAR not null
357-
: null;
354+
MessageChannel gwErrorChannel = gateway.getErrorChannel();
355+
String errorChannel = gwErrorChannel != null ? gwErrorChannel.toString() : null;
356+
MessageChannel gwRequestChannel = gateway.getRequestChannel();
357+
String requestChannel = gwRequestChannel != null ? gwRequestChannel.toString() : null;
358358
return new MessageGatewayNode(this.nodeId.incrementAndGet(), name, gateway,
359359
requestChannel, errorChannel);
360360
}

spring-integration-groovy/src/main/java/org/springframework/integration/groovy/GroovyCommandMessageProcessor.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -17,6 +17,7 @@
1717
package org.springframework.integration.groovy;
1818

1919
import java.util.Map;
20+
import java.util.UUID;
2021

2122
import org.springframework.integration.scripting.AbstractScriptExecutingMessageProcessor;
2223
import org.springframework.integration.scripting.DefaultScriptVariableGenerator;
@@ -28,6 +29,7 @@
2829
import org.springframework.scripting.support.StaticScriptSource;
2930
import org.springframework.util.Assert;
3031
import org.springframework.util.CollectionUtils;
32+
import org.springframework.util.ObjectUtils;
3133

3234
import groovy.lang.Binding;
3335
import groovy.lang.GString;
@@ -38,6 +40,7 @@
3840
* @author Oleg Zhurakousky
3941
* @author Artem Bilan
4042
* @author Stefan Reuter
43+
* @author Gary Russell
4144
* @since 2.0
4245
*/
4346
public class GroovyCommandMessageProcessor extends AbstractScriptExecutingMessageProcessor<Object> {
@@ -133,7 +136,9 @@ protected Object executeScript(ScriptSource scriptSource, Map<String, Object> va
133136

134137
protected String generateScriptName(Message<?> message) {
135138
// Don't use the same script (class) name for all invocations by default
136-
return getClass().getSimpleName() + message.getHeaders().getId().toString().replaceAll("-", "");
139+
UUID id = message.getHeaders().getId();
140+
return getClass().getSimpleName()
141+
+ (id != null ? id.toString().replaceAll("-", "") : ObjectUtils.getIdentityHexString(message));
137142
}
138143

139144
}

0 commit comments

Comments
 (0)