Skip to content

Commit 563f526

Browse files
garyrussellartembilan
authored andcommitted
Sonar Fixes
Critical smells for packages `o.s.i.i*`. * Polishing * Polishing * Missed saving a file. * Polishing - PR Comments * More PR comments.
1 parent 4760c54 commit 563f526

17 files changed

+95
-39
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ public Object resolveArgument(MethodParameter parameter, Message<?> message) thr
6262
Collection<Message<?>> messages = (Collection<Message<?>>) payload;
6363

6464
if (!this.expressionCache.containsKey(parameter)) {
65-
Payloads payloads = parameter.getParameterAnnotation(Payloads.class); // NOSONAR never null - supportsParameter()
66-
String expression = payloads.value();
65+
Payloads payloads = parameter.getParameterAnnotation(Payloads.class);
66+
String expression = payloads.value(); // NOSONAR never null - supportsParameter()
6767
if (StringUtils.hasText(expression)) {
6868
this.expressionCache.put(parameter, EXPRESSION_PARSER.parseExpression("![payload." + expression + "]"));
6969
}

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

Lines changed: 4 additions & 1 deletion
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-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.
@@ -16,16 +16,19 @@
1616

1717
package org.springframework.integration.mapping;
1818

19+
import org.springframework.lang.Nullable;
1920
import org.springframework.messaging.Message;
2021

2122
/**
2223
* Strategy interface for mapping from a {@link Message} to an Object.
2324
*
2425
* @author Mark Fisher
26+
* @author Gary Russell
2527
*/
2628
@FunctionalInterface
2729
public interface OutboundMessageMapper<T> {
2830

31+
@Nullable
2932
T fromMessage(Message<?> message) throws Exception;
3033

3134
}

spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/TcpOutboundGateway.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.springframework.expression.spel.support.StandardEvaluationContext;
3232
import org.springframework.integration.MessageTimeoutException;
3333
import org.springframework.integration.expression.ExpressionUtils;
34+
import org.springframework.integration.expression.ValueExpression;
3435
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
3536
import org.springframework.integration.ip.IpHeaders;
3637
import org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory;
@@ -62,6 +63,8 @@
6263
public class TcpOutboundGateway extends AbstractReplyProducingMessageHandler
6364
implements TcpSender, TcpListener, Lifecycle {
6465

66+
private static final long DEFAULT_REMOTE_TIMEOUT = 10_000L;
67+
6568
private static final int DEFAULT_SECOND_CHANCE_DELAY = 2;
6669

6770
private final Map<String, AsyncReply> pendingReplies = new ConcurrentHashMap<>();
@@ -72,10 +75,9 @@ public class TcpOutboundGateway extends AbstractReplyProducingMessageHandler
7275

7376
private boolean isSingleUse;
7477

75-
private Expression remoteTimeoutExpression = new LiteralExpression("10000");
78+
private Expression remoteTimeoutExpression = new ValueExpression<>(DEFAULT_REMOTE_TIMEOUT);
7679

7780
private long requestTimeout = 10000;
78-
7981
private EvaluationContext evaluationContext = new StandardEvaluationContext();
8082

8183
private boolean evaluationContextSet;
@@ -148,8 +150,16 @@ protected Object handleRequestMessage(Message<?> requestMessage) {
148150
}
149151
}
150152
connection = this.connectionFactory.getConnection();
151-
AsyncReply reply = new AsyncReply(this.remoteTimeoutExpression.getValue(this.evaluationContext,
152-
requestMessage, Long.class));
153+
Long remoteTimeout = this.remoteTimeoutExpression.getValue(this.evaluationContext, requestMessage,
154+
Long.class);
155+
if (remoteTimeout == null) {
156+
remoteTimeout = DEFAULT_REMOTE_TIMEOUT;
157+
if (logger.isWarnEnabled()) {
158+
logger.warn("remoteTimeoutExpression evaluated to null; falling back to default for message "
159+
+ requestMessage);
160+
}
161+
}
162+
AsyncReply reply = new AsyncReply(remoteTimeout);
153163
connectionId = connection.getConnectionId();
154164
this.pendingReplies.put(connectionId, reply);
155165
if (logger.isDebugEnabled()) {

spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractConnectionFactory.java

Lines changed: 3 additions & 1 deletion
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-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.
@@ -314,13 +314,15 @@ public int getPort() {
314314
/**
315315
* @return the listener
316316
*/
317+
@Nullable
317318
public TcpListener getListener() {
318319
return this.listener;
319320
}
320321

321322
/**
322323
* @return the sender
323324
*/
325+
@Nullable
324326
public TcpSender getSender() {
325327
return this.sender;
326328
}

spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractServerConnectionFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ protected void postProcessServerSocket(ServerSocket serverSocket) {
154154
*
155155
* @return the localAddress
156156
*/
157+
@Nullable
157158
public String getLocalAddress() {
158159
return this.localAddress;
159160
}

spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/DefaultTcpNioSSLConnectionSupport.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@ public TcpNioConnection createNewConnection(SocketChannel socketChannel, boolean
8181
postProcessSSLEngine(sslEngine);
8282
if (this.sslVerifyHost) {
8383
SSLParameters sslParameters = sslEngine.getSSLParameters();
84-
if (sslParameters == null) {
85-
sslParameters = new SSLParameters();
86-
}
8784
// HTTPS works for any TCP connection.
8885
// It checks SAN (Subject Alternative Name) as well as CN.
8986
sslParameters.setEndpointIdentificationAlgorithm("HTTPS");

spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/DefaultTcpSocketSupport.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ public void postProcessSocket(Socket socket) {
6666
if (this.sslVerifyHost && socket instanceof SSLSocket) {
6767
SSLSocket sslSocket = (SSLSocket) socket;
6868
SSLParameters sslParameters = sslSocket.getSSLParameters();
69-
if (sslParameters == null) {
70-
sslParameters = new SSLParameters();
71-
}
7269
// HTTPS works for any TCP connection.
7370
// It checks SAN (Subject Alternative Name) as well as CN.
7471
sslParameters.setEndpointIdentificationAlgorithm("HTTPS");

spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/FailoverClientConnectionFactory.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,16 @@ public boolean onMessage(Message<?> message) {
363363
messageBuilder.setHeader(IpHeaders.ACTUAL_CONNECTION_ID,
364364
message.getHeaders().get(IpHeaders.CONNECTION_ID));
365365
}
366-
return this.getListener().onMessage(messageBuilder.build());
366+
TcpListener listener = getListener();
367+
if (listener == null) {
368+
if (this.logger.isDebugEnabled()) {
369+
logger.debug("No listener for " + message);
370+
}
371+
return false;
372+
}
373+
else {
374+
return listener.onMessage(messageBuilder.build());
375+
}
367376
}
368377
else {
369378
if (logger.isDebugEnabled()) {

spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpConnection.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public interface TcpConnection extends Runnable {
6161
* @return The payload.
6262
* @throws Exception Any Exception.
6363
*/
64+
@Nullable
6465
Object getPayload() throws Exception;
6566

6667
/**
@@ -104,6 +105,7 @@ public interface TcpConnection extends Runnable {
104105
/**
105106
* @return this connection's listener
106107
*/
108+
@Nullable
107109
TcpListener getListener();
108110

109111
/**

spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpConnectionInterceptorFactoryChain.java

Lines changed: 4 additions & 1 deletion
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-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.
@@ -18,6 +18,8 @@
1818

1919
import java.util.Arrays;
2020

21+
import org.springframework.lang.Nullable;
22+
2123
/**
2224
* @author Gary Russell
2325
* @since 2.0
@@ -27,6 +29,7 @@ public class TcpConnectionInterceptorFactoryChain {
2729

2830
private TcpConnectionInterceptorFactory[] interceptorFactories;
2931

32+
@Nullable
3033
public TcpConnectionInterceptorFactory[] getInterceptorFactories() {
3134
return this.interceptorFactories; //NOSONAR
3235
}

0 commit comments

Comments
 (0)