From 12bc24dd02955892547474b46ad8a9319e7ecae2 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Fri, 26 Oct 2018 13:53:54 -0400 Subject: [PATCH] File, FTP, IP Sonar Fixes --- .../integration/mapping/InboundMessageMapper.java | 3 ++- .../integration/file/FileWritingMessageHandler.java | 2 +- .../integration/ftp/inbound/FtpInboundFileSynchronizer.java | 2 +- .../ip/tcp/connection/AbstractClientConnectionFactory.java | 4 +++- .../ip/tcp/connection/AbstractConnectionFactory.java | 5 ++++- .../ip/tcp/connection/AbstractServerConnectionFactory.java | 4 +++- .../integration/ip/tcp/connection/TcpConnection.java | 5 ++++- .../integration/ip/tcp/connection/TcpConnectionSupport.java | 3 ++- .../integration/ip/tcp/connection/TcpMessageMapper.java | 1 + .../integration/ip/tcp/connection/TcpNetConnection.java | 5 ++++- .../ip/tcp/connection/TcpNetServerConnectionFactory.java | 2 ++ .../ip/tcp/connection/TcpNioClientConnectionFactory.java | 2 +- .../integration/ip/tcp/connection/TcpNioConnection.java | 4 ++++ .../ip/tcp/connection/TcpNioServerConnectionFactory.java | 3 +++ .../integration/ip/udp/DatagramPacketMessageMapper.java | 1 + 15 files changed, 36 insertions(+), 10 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/mapping/InboundMessageMapper.java b/spring-integration-core/src/main/java/org/springframework/integration/mapping/InboundMessageMapper.java index 6b46df2df9..8e18861745 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/mapping/InboundMessageMapper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/mapping/InboundMessageMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,6 +49,7 @@ public interface InboundMessageMapper { * @throws Exception the exception thrown by the underlying mapper implementation * @since 5.0 */ + @Nullable Message toMessage(T object, @Nullable Map headers) throws Exception; } diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java b/spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java index 14b975ddfb..ab26a4ce61 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java @@ -449,7 +449,7 @@ public class FileWritingMessageHandler extends AbstractReplyProducingMessageHand if (this.destinationDirectoryExpression instanceof LiteralExpression) { final File directory = - new File(this.destinationDirectoryExpression.getValue(this.evaluationContext, null, String.class)); + new File(this.destinationDirectoryExpression.getValue(this.evaluationContext, String.class)); validateDestinationDirectory(directory, this.autoCreateDirectory); } diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/inbound/FtpInboundFileSynchronizer.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/inbound/FtpInboundFileSynchronizer.java index 0d55caf66f..b44b04fda0 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/inbound/FtpInboundFileSynchronizer.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/inbound/FtpInboundFileSynchronizer.java @@ -42,7 +42,7 @@ public class FtpInboundFileSynchronizer extends AbstractInboundFileSynchronizer< */ public FtpInboundFileSynchronizer(SessionFactory sessionFactory) { super(sessionFactory); - doSetRemoteDirectoryExpression(new LiteralExpression(null)); + doSetRemoteDirectoryExpression(new LiteralExpression(null)); // NOSONAR - LE can actually handle null ok doSetFilter(new FtpPersistentAcceptOnceFileListFilter(new SimpleMetadataStore(), "ftpMessageSource")); } diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractClientConnectionFactory.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractClientConnectionFactory.java index 0244592130..c95dd78749 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractClientConnectionFactory.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractClientConnectionFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; import org.springframework.context.ApplicationEventPublisher; +import org.springframework.lang.Nullable; /** * Abstract class for client connection factories; client connection factories @@ -79,6 +80,7 @@ public abstract class AbstractClientConnectionFactory extends AbstractConnection return obtainNewConnection(); } + @Nullable protected final TcpConnectionSupport obtainSharedConnection() throws InterruptedException { this.theConnectionLock.readLock().lockInterruptibly(); try { diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractConnectionFactory.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractConnectionFactory.java index f8d3445dc7..55c7117596 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractConnectionFactory.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractConnectionFactory.java @@ -48,6 +48,7 @@ import org.springframework.core.serializer.Deserializer; import org.springframework.core.serializer.Serializer; import org.springframework.integration.context.IntegrationObjectSupport; import org.springframework.integration.ip.tcp.serializer.ByteArrayCrLfSerializer; +import org.springframework.lang.Nullable; import org.springframework.messaging.MessagingException; import org.springframework.util.Assert; @@ -610,8 +611,10 @@ public abstract class AbstractConnectionFactory extends IntegrationObjectSupport * @param connections Map of connections. * @throws IOException Any IOException. */ - protected void processNioSelections(int selectionCount, final Selector selector, ServerSocketChannel server, + protected void processNioSelections(int selectionCount, final Selector selector, + @Nullable ServerSocketChannel server, Map connections) throws IOException { + final long now = System.currentTimeMillis(); rescheduleDelayedReads(selector, now); if (this.soTimeout > 0 || diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractServerConnectionFactory.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractServerConnectionFactory.java index b82b044d0a..bae07da2c4 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractServerConnectionFactory.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractServerConnectionFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2001-2016 the original author or authors. + * Copyright 2001-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ import java.util.Date; import org.springframework.context.ApplicationEventPublisher; import org.springframework.core.task.TaskRejectedException; import org.springframework.integration.context.OrderlyShutdownCapable; +import org.springframework.lang.Nullable; import org.springframework.scheduling.SchedulingAwareRunnable; import org.springframework.scheduling.TaskScheduler; import org.springframework.util.Assert; @@ -66,6 +67,7 @@ public abstract class AbstractServerConnectionFactory extends AbstractConnection } @Override + @Nullable public SocketAddress getServerSocketAddress() { return null; } diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpConnection.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpConnection.java index bbf0681976..1e1e54c218 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpConnection.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpConnection.java @@ -1,5 +1,5 @@ /* - * Copyright 2001-2016 the original author or authors. + * Copyright 2001-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ import javax.net.ssl.SSLSession; import org.springframework.core.serializer.Deserializer; import org.springframework.core.serializer.Serializer; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; /** @@ -116,6 +117,7 @@ public interface TcpConnection extends Runnable { * associated with the connection, but the object should be treated as opaque * and ONLY used as a key. */ + @Nullable Object getDeserializerStateKey(); /** @@ -123,6 +125,7 @@ public interface TcpConnection extends Runnable { * null otherwise. * @since 4.2 */ + @Nullable SSLSession getSslSession(); /** diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpConnectionSupport.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpConnectionSupport.java index decc184564..8857463044 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpConnectionSupport.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpConnectionSupport.java @@ -34,6 +34,7 @@ import org.springframework.core.serializer.Deserializer; import org.springframework.core.serializer.Serializer; import org.springframework.integration.ip.IpHeaders; import org.springframework.integration.ip.tcp.serializer.AbstractByteArraySerializer; +import org.springframework.lang.Nullable; import org.springframework.messaging.MessagingException; import org.springframework.messaging.support.ErrorMessage; import org.springframework.util.Assert; @@ -93,7 +94,7 @@ public abstract class TcpConnectionSupport implements TcpConnection { this(null); } - public TcpConnectionSupport(ApplicationEventPublisher applicationEventPublisher) { + public TcpConnectionSupport(@Nullable ApplicationEventPublisher applicationEventPublisher) { this.server = false; this.applicationEventPublisher = applicationEventPublisher; this.socketInfo = null; diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpMessageMapper.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpMessageMapper.java index a5b6306c56..641ea18e98 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpMessageMapper.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpMessageMapper.java @@ -238,6 +238,7 @@ public class TcpMessageMapper implements * @param connection the connection. * @return A Map of {@code } headers to be added to the message. */ + @Nullable protected Map supplyCustomHeaders(TcpConnection connection) { return null; } diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetConnection.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetConnection.java index 91db1dd3a8..12a5c54ded 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetConnection.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetConnection.java @@ -1,5 +1,5 @@ /* - * Copyright 2001-2017 the original author or authors. + * Copyright 2001-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,6 +31,7 @@ import org.springframework.context.ApplicationEventPublisher; import org.springframework.core.serializer.Deserializer; import org.springframework.core.serializer.Serializer; import org.springframework.integration.ip.tcp.serializer.SoftEndOfStreamException; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessagingException; import org.springframework.scheduling.SchedulingAwareRunnable; @@ -129,6 +130,7 @@ public class TcpNetConnection extends TcpConnectionSupport implements Scheduling } @Override + @Nullable public Object getDeserializerStateKey() { try { return inputStream(); @@ -139,6 +141,7 @@ public class TcpNetConnection extends TcpConnectionSupport implements Scheduling } @Override + @Nullable public SSLSession getSslSession() { if (this.socket instanceof SSLSocket) { return ((SSLSocket) this.socket).getSession(); diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetServerConnectionFactory.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetServerConnectionFactory.java index cbb48beda4..72d3e53723 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetServerConnectionFactory.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetServerConnectionFactory.java @@ -26,6 +26,7 @@ import java.net.SocketTimeoutException; import javax.net.ServerSocketFactory; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -70,6 +71,7 @@ public class TcpNetServerConnectionFactory extends AbstractServerConnectionFacto } @Override + @Nullable public SocketAddress getServerSocketAddress() { if (this.serverSocket != null) { return this.serverSocket.getLocalSocketAddress(); diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioClientConnectionFactory.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioClientConnectionFactory.java index 5894e99fe5..123c40308c 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioClientConnectionFactory.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioClientConnectionFactory.java @@ -180,7 +180,7 @@ public class TcpNioClientConnectionFactory extends } } } - this.processNioSelections(selectionCount, this.selector, null, this.channelMap); + processNioSelections(selectionCount, this.selector, null, this.channelMap); } } catch (ClosedSelectorException cse) { diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioConnection.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioConnection.java index ecaab82802..aac272561a 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioConnection.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioConnection.java @@ -42,6 +42,7 @@ import org.springframework.context.ApplicationEventPublisher; import org.springframework.core.serializer.Serializer; import org.springframework.integration.ip.tcp.serializer.SoftEndOfStreamException; import org.springframework.integration.util.CompositeExecutor; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessagingException; import org.springframework.util.Assert; @@ -183,6 +184,7 @@ public class TcpNioConnection extends TcpConnectionSupport { } @Override + @Nullable public SSLSession getSslSession() { return null; } @@ -332,6 +334,7 @@ public class TcpNioConnection extends TcpConnectionSupport { * @return The Message or null if no data is available. * @throws IOException */ + @Nullable private synchronized Message convert() throws Exception { if (logger.isTraceEnabled()) { logger.trace(getConnectionId() + " checking data avail (convert): " + this.channelInputStream.available() + @@ -711,6 +714,7 @@ public class TcpNioConnection extends TcpConnectionSupport { return bite; } + @Nullable private byte[] getNextBuffer() throws IOException { byte[] buffer = null; while (buffer == null) { diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioServerConnectionFactory.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioServerConnectionFactory.java index 33dfdfa602..a82cd72bbe 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioServerConnectionFactory.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioServerConnectionFactory.java @@ -30,6 +30,7 @@ import java.nio.channels.SocketChannel; import java.util.HashMap; import java.util.Map; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -85,6 +86,7 @@ public class TcpNioServerConnectionFactory extends AbstractServerConnectionFacto } @Override + @Nullable public SocketAddress getServerSocketAddress() { if (this.serverChannel != null) { try { @@ -235,6 +237,7 @@ public class TcpNioServerConnectionFactory extends AbstractServerConnectionFacto } } + @Nullable private TcpNioConnection createTcpNioConnection(SocketChannel socketChannel) { try { TcpNioConnection connection = this.tcpNioConnectionSupport.createNewConnection(socketChannel, true, diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/udp/DatagramPacketMessageMapper.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/udp/DatagramPacketMessageMapper.java index f26deccaa6..dd03f66c59 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/udp/DatagramPacketMessageMapper.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/udp/DatagramPacketMessageMapper.java @@ -204,6 +204,7 @@ public class DatagramPacketMessageMapper implements InboundMessageMapper toMessage(DatagramPacket packet, @Nullable Map headers) throws Exception { int offset = packet.getOffset(); int length = packet.getLength();