Skip to content

Commit e71e250

Browse files
committed
Fix new Sonar smells
1 parent 0efcf24 commit e71e250

File tree

7 files changed

+115
-118
lines changed

7 files changed

+115
-118
lines changed

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

Lines changed: 10 additions & 3 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.
@@ -22,19 +22,24 @@
2222
import java.net.Socket;
2323

2424
import org.springframework.context.ApplicationEventPublisher;
25+
import org.springframework.lang.Nullable;
2526

2627

2728
/**
2829
* Default implementation of {@link TcpNetConnectionSupport}.
30+
*
2931
* @author Gary Russell
32+
* @author Artem Bilan
33+
*
3034
* @since 5.0
3135
*
3236
*/
3337
public class DefaultTcpNetConnectionSupport extends AbstractTcpConnectionSupport implements TcpNetConnectionSupport {
3438

3539
@Override
3640
public TcpNetConnection createNewConnection(Socket socket, boolean server, boolean lookupHost,
37-
ApplicationEventPublisher applicationEventPublisher, String connectionFactoryName) {
41+
@Nullable ApplicationEventPublisher applicationEventPublisher, String connectionFactoryName) {
42+
3843
if (isPushbackCapable()) {
3944
return new PushBackTcpNetConnection(socket, server, lookupHost, applicationEventPublisher,
4045
connectionFactoryName, getPushbackBufferSize());
@@ -55,7 +60,9 @@ private static final class PushBackTcpNetConnection extends TcpNetConnection {
5560
private volatile InputStream wrapped;
5661

5762
PushBackTcpNetConnection(Socket socket, boolean server, boolean lookupHost,
58-
ApplicationEventPublisher applicationEventPublisher, String connectionFactoryName, int bufferSize) {
63+
@Nullable ApplicationEventPublisher applicationEventPublisher, String connectionFactoryName,
64+
int bufferSize) {
65+
5966
super(socket, server, lookupHost, applicationEventPublisher, connectionFactoryName);
6067
this.pushbackBufferSize = bufferSize;
6168
this.connectionId = "pushback:" + super.getConnectionId();

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

Lines changed: 4 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.
@@ -38,7 +38,8 @@ public class DefaultTcpNioConnectionSupport extends AbstractTcpConnectionSupport
3838

3939
@Override
4040
public TcpNioConnection createNewConnection(SocketChannel socketChannel, boolean server, boolean lookupHost,
41-
ApplicationEventPublisher applicationEventPublisher, String connectionFactoryName) {
41+
@Nullable ApplicationEventPublisher applicationEventPublisher, String connectionFactoryName) {
42+
4243
if (isPushbackCapable()) {
4344
return new PushBackTcpNioConnection(socketChannel, server, lookupHost, applicationEventPublisher,
4445
connectionFactoryName, getPushbackBufferSize());
@@ -60,7 +61,7 @@ private static final class PushBackTcpNioConnection extends TcpNioConnection {
6061
private volatile InputStream wrapped;
6162

6263
PushBackTcpNioConnection(SocketChannel socketChannel, boolean server, boolean lookupHost,
63-
ApplicationEventPublisher applicationEventPublisher, @Nullable String connectionFactoryName,
64+
@Nullable ApplicationEventPublisher applicationEventPublisher, @Nullable String connectionFactoryName,
6465
int bufferSize) {
6566

6667
super(socketChannel, server, lookupHost, applicationEventPublisher, connectionFactoryName);

spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/DefaultTcpNioSSLConnectionSupport.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.
@@ -27,6 +27,7 @@
2727
import javax.net.ssl.SSLParameters;
2828

2929
import org.springframework.context.ApplicationEventPublisher;
30+
import org.springframework.lang.Nullable;
3031
import org.springframework.util.Assert;
3132

3233
/**
@@ -75,7 +76,7 @@ public DefaultTcpNioSSLConnectionSupport(TcpSSLContextSupport sslContextSupport,
7576
*/
7677
@Override
7778
public TcpNioConnection createNewConnection(SocketChannel socketChannel, boolean server, boolean lookupHost,
78-
ApplicationEventPublisher applicationEventPublisher, String connectionFactoryName) {
79+
@Nullable ApplicationEventPublisher applicationEventPublisher, String connectionFactoryName) {
7980

8081
SSLEngine sslEngine = this.sslContext.createSSLEngine();
8182
postProcessSSLEngine(sslEngine);
@@ -119,7 +120,8 @@ private static final class PushBackTcpNioSSLConnection extends TcpNioSSLConnecti
119120
private volatile InputStream wrapped;
120121

121122
PushBackTcpNioSSLConnection(SocketChannel socketChannel, boolean server, boolean lookupHost,
122-
ApplicationEventPublisher applicationEventPublisher, String connectionFactoryName, SSLEngine sslEngine,
123+
@Nullable ApplicationEventPublisher applicationEventPublisher, String connectionFactoryName,
124+
SSLEngine sslEngine,
123125
int bufferSize) {
124126

125127
super(socketChannel, server, lookupHost, applicationEventPublisher, connectionFactoryName, sslEngine);

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2001-2019 the original author or authors.
2+
* Copyright 2001-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.
@@ -115,7 +115,7 @@ public TcpConnectionSupport(@Nullable ApplicationEventPublisher applicationEvent
115115
* during event publishing, may be null, in which case "unknown" will be used.
116116
*/
117117
public TcpConnectionSupport(Socket socket, boolean server, boolean lookupHost,
118-
ApplicationEventPublisher applicationEventPublisher,
118+
@Nullable ApplicationEventPublisher applicationEventPublisher,
119119
@Nullable String connectionFactoryName) {
120120

121121
this.socketInfo = new SocketInfo(socket);
@@ -359,21 +359,15 @@ protected final void sendExceptionToListener(Exception e) {
359359
}
360360

361361
protected void publishConnectionOpenEvent() {
362-
TcpConnectionEvent event = new TcpConnectionOpenEvent(this,
363-
getConnectionFactoryName());
364-
doPublish(event);
362+
doPublish(new TcpConnectionOpenEvent(this, getConnectionFactoryName()));
365363
}
366364

367365
protected void publishConnectionCloseEvent() {
368-
TcpConnectionEvent event = new TcpConnectionCloseEvent(this,
369-
getConnectionFactoryName());
370-
doPublish(event);
366+
doPublish(new TcpConnectionCloseEvent(this, getConnectionFactoryName()));
371367
}
372368

373369
protected void publishConnectionExceptionEvent(Throwable t) {
374-
TcpConnectionEvent event = new TcpConnectionExceptionEvent(this,
375-
getConnectionFactoryName(), t);
376-
doPublish(event);
370+
doPublish(new TcpConnectionExceptionEvent(this, getConnectionFactoryName(), t));
377371
}
378372

379373
/**

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2001-2019 the original author or authors.
2+
* Copyright 2001-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.
@@ -42,6 +42,7 @@
4242
* A TcpConnection that uses and underlying {@link Socket}.
4343
*
4444
* @author Gary Russell
45+
*
4546
* @since 2.0
4647
*
4748
*/
@@ -68,7 +69,8 @@ public class TcpNetConnection extends TcpConnectionSupport implements Scheduling
6869
* during event publishing, may be null, in which case "unknown" will be used.
6970
*/
7071
public TcpNetConnection(Socket socket, boolean server, boolean lookupHost,
71-
ApplicationEventPublisher applicationEventPublisher, String connectionFactoryName) {
72+
@Nullable ApplicationEventPublisher applicationEventPublisher, String connectionFactoryName) {
73+
7274
super(socket, server, lookupHost, applicationEventPublisher, connectionFactoryName);
7375
this.socket = socket;
7476
}

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

Lines changed: 14 additions & 18 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.
@@ -53,6 +53,8 @@
5353
*
5454
* @author Gary Russell
5555
* @author John Anderson
56+
* @author Artem Bilan
57+
*
5658
* @since 2.0
5759
*
5860
*/
@@ -106,7 +108,7 @@ public class TcpNioConnection extends TcpConnectionSupport {
106108
* @param connectionFactoryName The name of the connection factory creating this connection.
107109
*/
108110
public TcpNioConnection(SocketChannel socketChannel, boolean server, boolean lookupHost,
109-
ApplicationEventPublisher applicationEventPublisher,
111+
@Nullable ApplicationEventPublisher applicationEventPublisher,
110112
@Nullable String connectionFactoryName) {
111113

112114
super(socketChannel.socket(), server, lookupHost, applicationEventPublisher, connectionFactoryName);
@@ -272,8 +274,7 @@ public void run() {
272274
}
273275
catch (Exception e) {
274276
if (logger.isTraceEnabled()) {
275-
logger.error("Read exception " +
276-
getConnectionId(), e);
277+
logger.error("Read exception " + getConnectionId(), e);
277278
}
278279
else if (!isNoReadErrorOnClose()) {
279280
logger.error("Read exception " +
@@ -386,13 +387,11 @@ private synchronized Message<?> convert() throws IOException {
386387

387388
private void sendToChannel(Message<?> message) {
388389
try {
389-
if (message != null) {
390-
TcpListener listener = getListener();
391-
if (listener == null) {
392-
throw new NoListenerException("No listener");
393-
}
394-
listener.onMessage(message);
390+
TcpListener listener = getListener();
391+
if (listener == null) {
392+
throw new NoListenerException("No listener");
395393
}
394+
listener.onMessage(message);
396395
}
397396
catch (Exception e) {
398397
if (e instanceof NoListenerException) { // could also be thrown by an interceptor
@@ -425,19 +424,19 @@ private void doRead() throws IOException {
425424
checkForAssembler();
426425

427426
if (logger.isTraceEnabled()) {
428-
logger.trace("Before read:" + this.rawBuffer.position() + "/" + this.rawBuffer.limit());
427+
logger.trace("Before read: " + this.rawBuffer.position() + "/" + this.rawBuffer.limit());
429428
}
430429
int len = this.socketChannel.read(this.rawBuffer);
431430
if (len < 0) {
432431
this.writingToPipe = false;
433432
closeConnection(true);
434433
}
435434
if (logger.isTraceEnabled()) {
436-
logger.trace("After read:" + this.rawBuffer.position() + "/" + this.rawBuffer.limit());
435+
logger.trace("After read: " + this.rawBuffer.position() + "/" + this.rawBuffer.limit());
437436
}
438437
this.rawBuffer.flip();
439438
if (logger.isTraceEnabled()) {
440-
logger.trace("After flip:" + this.rawBuffer.position() + "/" + this.rawBuffer.limit());
439+
logger.trace("After flip: " + this.rawBuffer.position() + "/" + this.rawBuffer.limit());
441440
}
442441
if (logger.isDebugEnabled()) {
443442
logger.debug("Read " + this.rawBuffer.limit() + " into raw buffer");
@@ -506,9 +505,7 @@ public void readPacket() {
506505
closeConnection(true);
507506
}
508507
catch (Exception e) {
509-
logger.error("Exception on Read " +
510-
getConnectionId() + " " +
511-
e.getMessage(), e);
508+
logger.error("Exception on Read " + getConnectionId() + " " + e.getMessage(), e);
512509
closeConnection(true);
513510
}
514511
}
@@ -535,8 +532,7 @@ public void setTaskExecutor(Executor taskExecutor) {
535532
}
536533

537534
/**
538-
* If true, connection will attempt to use direct buffers where
539-
* possible.
535+
* If true, connection will attempt to use direct buffers where possible.
540536
* @param usingDirectBuffers the usingDirectBuffers to set.
541537
*/
542538
public void setUsingDirectBuffers(boolean usingDirectBuffers) {

0 commit comments

Comments
 (0)