Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.integration.ftp.config;

import java.util.Objects;

import org.w3c.dom.Element;

import org.springframework.beans.factory.config.BeanDefinition;
Expand Down Expand Up @@ -55,7 +57,8 @@ protected void postProcessBuilder(BeanDefinitionBuilder builder, Element element
.iterator()
.next()
.getValue();
templateDefinition.getPropertyValues() // NOSONAR never null

Objects.requireNonNull(templateDefinition).getPropertyValues()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be correct to say that we don't expect the templateDefinition returned from the builder should never be null?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you say is correct , but contract enforces us.
I wouldn’t spend too much time on XML parsers: I anticipate their deprecation and removal at some point.
Plus , this is not a critical execution path, so it is OK to say nothing and just follow the contract.

.add("existsMode", FtpRemoteFileTemplate.ExistsMode.NLST);
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "chmod", "chmodOctal");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.integration.ftp.config;

import java.util.Objects;

import org.w3c.dom.Element;

import org.springframework.beans.factory.config.BeanDefinition;
Expand Down Expand Up @@ -66,7 +68,8 @@ protected void postProcessBuilder(BeanDefinitionBuilder builder, Element element
.iterator()
.next()
.getValue();
templateDefinition.getPropertyValues() // NOSONAR never null

Objects.requireNonNull(templateDefinition).getPropertyValues()
.add("existsMode", FtpRemoteFileTemplate.ExistsMode.NLST);

IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "working-dir-expression",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* Provides classes for configuration - parsers, namespace handlers.
*/
@org.jspecify.annotations.NullMarked
package org.springframework.integration.ftp.config;
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Comparator;

import org.apache.commons.net.ftp.FTPFile;
import org.jspecify.annotations.Nullable;

import org.springframework.integration.file.remote.MessageSessionCallback;
import org.springframework.integration.file.remote.RemoteFileTemplate;
Expand All @@ -28,7 +29,6 @@
import org.springframework.integration.file.support.FileExistsMode;
import org.springframework.integration.ftp.gateway.FtpOutboundGateway;
import org.springframework.integration.ftp.session.FtpRemoteFileTemplate;
import org.springframework.lang.Nullable;

/**
* The factory for FTP components.
Expand Down Expand Up @@ -216,7 +216,7 @@ public static FtpOutboundGatewaySpec outboundGateway(RemoteFileTemplate<FTPFile>
* @see RemoteFileTemplate
*/
public static FtpOutboundGatewaySpec outboundGateway(RemoteFileTemplate<FTPFile> remoteFileTemplate,
AbstractRemoteFileOutboundGateway.Command command, String expression) {
AbstractRemoteFileOutboundGateway.Command command, @Nullable String expression) {

return outboundGateway(remoteFileTemplate, command.getCommand(), expression);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Comparator;

import org.apache.commons.net.ftp.FTPFile;
import org.jspecify.annotations.Nullable;

import org.springframework.integration.file.dsl.RemoteFileInboundChannelAdapterSpec;
import org.springframework.integration.file.filters.CompositeFileListFilter;
Expand All @@ -31,7 +32,6 @@
import org.springframework.integration.ftp.inbound.FtpInboundFileSynchronizer;
import org.springframework.integration.ftp.inbound.FtpInboundFileSynchronizingMessageSource;
import org.springframework.integration.metadata.SimpleMetadataStore;
import org.springframework.lang.Nullable;

/**
* A {@link RemoteFileInboundChannelAdapterSpec} for an {@link FtpInboundFileSynchronizingMessageSource}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Comparator;

import org.apache.commons.net.ftp.FTPFile;
import org.jspecify.annotations.Nullable;

import org.springframework.integration.file.dsl.RemoteFileStreamingInboundChannelAdapterSpec;
import org.springframework.integration.file.filters.CompositeFileListFilter;
Expand All @@ -29,7 +30,6 @@
import org.springframework.integration.ftp.filters.FtpSimplePatternFileListFilter;
import org.springframework.integration.ftp.inbound.FtpStreamingMessageSource;
import org.springframework.integration.metadata.SimpleMetadataStore;
import org.springframework.lang.Nullable;

/**
* A {@link RemoteFileStreamingInboundChannelAdapterSpec} for a {@link FtpStreamingMessageSource}.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/**
* Provides FTP Components for the Java DSL.
*/
@org.springframework.lang.NonNullApi
@org.springframework.lang.NonNullFields
@org.jspecify.annotations.NullMarked
package org.springframework.integration.ftp.dsl;
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public FtpRegexPatternFileListFilter(Pattern pattern) {

@Override
protected String getFilename(FTPFile file) {
return (file != null) ? file.getName() : null;
return file.getName();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public FtpSimplePatternFileListFilter(String pattern) {

@Override
protected String getFilename(FTPFile file) {
return (file != null) ? file.getName() : null;
return file.getName();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* Provides classes supporting FTP file filtering.
*/
@org.jspecify.annotations.NullMarked
package org.springframework.integration.ftp.filters;
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.jspecify.annotations.Nullable;

import org.springframework.expression.Expression;
import org.springframework.expression.spel.support.StandardEvaluationContext;
Expand All @@ -41,7 +42,6 @@
import org.springframework.integration.file.remote.session.SessionFactory;
import org.springframework.integration.ftp.session.FtpFileInfo;
import org.springframework.integration.ftp.session.FtpRemoteFileTemplate;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;

/**
Expand All @@ -54,8 +54,9 @@
*/
public class FtpOutboundGateway extends AbstractRemoteFileOutboundGateway<FTPFile> {

private Expression workingDirExpression;
private @Nullable Expression workingDirExpression;

@SuppressWarnings("NullAway.Init")
private StandardEvaluationContext evaluationContext;

/**
Expand Down Expand Up @@ -210,18 +211,18 @@ protected FTPFile enhanceNameWithSubDirectory(FTPFile file, String directory) {
}

@Override
protected List<?> ls(Message<?> message, Session<FTPFile> session, String dir) throws IOException {
protected List<?> ls(Message<?> message, Session<FTPFile> session, @Nullable String dir) throws IOException {
return doInWorkingDirectory(message, session, () -> super.ls(message, session, dir));
}

@Override
protected List<String> nlst(Message<?> message, Session<FTPFile> session, String dir) throws IOException {
protected List<String> nlst(Message<?> message, Session<FTPFile> session, @Nullable String dir) throws IOException {
return doInWorkingDirectory(message, session, () -> super.nlst(message, session, dir));
}

@Override
protected File get(Message<?> message, Session<FTPFile> session, String remoteDir, String remoteFilePath,
String remoteFilename, FTPFile fileInfoParam) throws IOException {
protected File get(Message<?> message, Session<FTPFile> session, @Nullable String remoteDir, String remoteFilePath,
String remoteFilename, @Nullable FTPFile fileInfoParam) throws IOException {

return doInWorkingDirectory(message, session,
() -> super.get(message, session, remoteDir, remoteFilePath, remoteFilename, fileInfoParam));
Expand Down Expand Up @@ -249,7 +250,7 @@ protected boolean mv(Message<?> message, Session<FTPFile> session, String remote
}

@Override
protected String put(Message<?> message, Session<FTPFile> session, String subDirectory) {
protected String put(Message<?> message, Session<FTPFile> session, @Nullable String subDirectory) {
try {
return doInWorkingDirectory(message, session,
() -> super.put(message, session, subDirectory));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* Provides classes supporting FTP gateways.
*/
@org.jspecify.annotations.NullMarked
package org.springframework.integration.ftp.gateway;
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ public class FtpInboundFileSynchronizer extends AbstractInboundFileSynchronizer<
* {@link org.springframework.integration.file.remote.session.Session} instances.
* @param sessionFactory The session factory.
*/
@SuppressWarnings("this-escape")
@SuppressWarnings({ "this-escape", "NullAway"})// The LiteralExpression can actually handle null ok
public FtpInboundFileSynchronizer(SessionFactory<FTPFile> sessionFactory) {
super(sessionFactory);
doSetRemoteDirectoryExpression(new LiteralExpression(null)); // NOSONAR - LE can actually handle null ok
doSetRemoteDirectoryExpression(new LiteralExpression(null));
doSetFilter(new FtpPersistentAcceptOnceFileListFilter(new SimpleMetadataStore(), "ftpMessageSource"));
}

@Override
protected boolean isFile(FTPFile file) {
return file != null && file.isFile();
return file.isFile();
}

@Override
protected String getFilename(FTPFile file) {
return (file != null ? file.getName() : null);
return file.getName();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Comparator;

import org.apache.commons.net.ftp.FTPFile;
import org.jspecify.annotations.Nullable;

import org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer;
import org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizingMessageSource;
Expand All @@ -31,6 +32,8 @@
* @author Josh Long
* @author Mark Fisher
* @author Oleg Zhurakousky
* @author Artem Bilan
*
* @since 2.0
*/
public class FtpInboundFileSynchronizingMessageSource extends AbstractInboundFileSynchronizingMessageSource<FTPFile> {
Expand All @@ -39,7 +42,9 @@ public FtpInboundFileSynchronizingMessageSource(AbstractInboundFileSynchronizer<
super(synchronizer);
}

public FtpInboundFileSynchronizingMessageSource(AbstractInboundFileSynchronizer<FTPFile> synchronizer, Comparator<File> comparator) {
public FtpInboundFileSynchronizingMessageSource(AbstractInboundFileSynchronizer<FTPFile> synchronizer,
@Nullable Comparator<File> comparator) {

super(synchronizer, comparator);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.List;

import org.apache.commons.net.ftp.FTPFile;
import org.jspecify.annotations.Nullable;

import org.springframework.integration.file.remote.AbstractFileInfo;
import org.springframework.integration.file.remote.AbstractRemoteFileStreamingMessageSource;
Expand Down Expand Up @@ -57,7 +58,7 @@ public FtpStreamingMessageSource(RemoteFileTemplate<FTPFile> template) {
* @param comparator the comparator.
*/
@SuppressWarnings("this-escape")
public FtpStreamingMessageSource(RemoteFileTemplate<FTPFile> template, Comparator<FTPFile> comparator) {
public FtpStreamingMessageSource(RemoteFileTemplate<FTPFile> template, @Nullable Comparator<FTPFile> comparator) {
super(template, comparator);
doSetFilter(new FtpPersistentAcceptOnceFileListFilter(new SimpleMetadataStore(), "ftpStreamingMessageSource"));
}
Expand All @@ -69,7 +70,7 @@ public String getComponentType() {

@Override
protected List<AbstractFileInfo<FTPFile>> asFileInfoList(Collection<FTPFile> files) {
List<AbstractFileInfo<FTPFile>> canonicalFiles = new ArrayList<AbstractFileInfo<FTPFile>>();
List<AbstractFileInfo<FTPFile>> canonicalFiles = new ArrayList<>();
for (FTPFile file : files) {
canonicalFiles.add(new FtpFileInfo(file));
}
Expand All @@ -78,7 +79,7 @@ protected List<AbstractFileInfo<FTPFile>> asFileInfoList(Collection<FTPFile> fil

@Override
protected boolean isDirectory(FTPFile file) {
return file != null && file.isDirectory();
return file.isDirectory();
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* Provides classes supporting inbound endpoints.
*/
@org.jspecify.annotations.NullMarked
package org.springframework.integration.ftp.inbound;
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* Provides classes for the FTP outbound channel adapter.
*/
@org.jspecify.annotations.NullMarked
package org.springframework.integration.ftp.outbound;
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,26 @@
import org.apache.ftpserver.ftplet.FtpletResult;

import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.util.Assert;

/**
* A listener for FTP events emitted by an Apache Mina ftp server.
* It emits selected events as Spring Framework {@code ApplicationEvent}s
* which are subclasses of {@link ApacheMinaFtpEvent}.
*
* @author Gary Russell
* @author Artem Bilan
*
* @since 5.2
*
*/
public class ApacheMinaFtplet extends DefaultFtplet
implements ApplicationEventPublisherAware, BeanNameAware, InitializingBean {
public class ApacheMinaFtplet extends DefaultFtplet implements ApplicationEventPublisherAware, BeanNameAware {

@SuppressWarnings("NullAway.Init")
private ApplicationEventPublisher applicationEventPublisher;

@SuppressWarnings("NullAway.Init")
private String beanName;

@Override
Expand All @@ -64,11 +65,6 @@ public String getBeanName() {
return this.beanName;
}

@Override
public void afterPropertiesSet() {
Assert.state(this.applicationEventPublisher != null, "An ApplicationEventPublisher is required");
}

@Override
public FtpletResult onConnect(FtpSession session) throws FtpException, IOException {
this.applicationEventPublisher.publishEvent(new SessionOpenedEvent(session));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* Provides classes related to FTP servers.
*/
@org.jspecify.annotations.NullMarked
package org.springframework.integration.ftp.server;
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.commons.net.ftp.FTPClientConfig;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
import org.jspecify.annotations.Nullable;

import org.springframework.integration.file.remote.session.SessionFactory;
import org.springframework.messaging.MessagingException;
Expand All @@ -46,13 +47,13 @@ public abstract class AbstractFtpSessionFactory<T extends FTPClient> implements

protected final Log logger = LogFactory.getLog(this.getClass()); // NOSONAR

private FTPClientConfig config;
private @Nullable FTPClientConfig config;

private String username;
private @Nullable String username;

private String host;
private @Nullable String host;

private String password;
private @Nullable String password;

private int port = FTP.DEFAULT_PORT;

Expand All @@ -64,11 +65,11 @@ public abstract class AbstractFtpSessionFactory<T extends FTPClient> implements

private String controlEncoding = FTP.DEFAULT_CONTROL_ENCODING;

private Integer connectTimeout;
private @Nullable Integer connectTimeout;

private Integer defaultTimeout;
private @Nullable Integer defaultTimeout;

private Integer dataTimeout;
private @Nullable Integer dataTimeout;

/**
* File types defined by {@link org.apache.commons.net.ftp.FTP} constants:
Expand Down Expand Up @@ -175,7 +176,7 @@ public FtpSession getSession() {
}

private T createClient() throws IOException {
final T client = this.createClientInstance();
final T client = createClientInstance();
Assert.notNull(client, "client must not be null");
client.configure(this.config);
Assert.hasText(this.username, "username is required");
Expand Down
Loading