From 2b9dac0c8fc20ebd952baf4674e1c4fc2362c77b Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Wed, 8 May 2024 16:11:53 -0400 Subject: [PATCH] Fix NPE in the `AbstractInboundFileSynchronizer` for remote dir Related to: #9129 The `remoteDirectoryPath` might be `null`, so it is not correct to attempt `remoteDirectoryPath.charAt(0)`. Plus `/null` is not correct path. * Use `/` for empty remote dir. * Check for `remoteDirectoryPath != null` (cherry picked from commit 467c96171e5d25d6542841c7beb8ac2b4fa2fc69) --- .../AbstractInboundFileSynchronizer.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java index 285740e664..bffe5e31ca 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java @@ -444,7 +444,7 @@ public abstract class AbstractInboundFileSynchronizer } } - protected boolean copyFileToLocalDirectory(String remoteDirectoryPath, // NOSONAR + protected boolean copyFileToLocalDirectory(@Nullable String remoteDirectoryPath, // NOSONAR @Nullable EvaluationContext localFileEvaluationContext, F remoteFile, File localDirectory, Session session) throws IOException { @@ -503,12 +503,15 @@ public abstract class AbstractInboundFileSynchronizer String host = hostPort.substring(0, colonIndex); String port = hostPort.substring(colonIndex + 1); try { + String remoteDir = "/"; + if (remoteDirectoryPath != null) { + remoteDir = + remoteDirectoryPath.charAt(0) == '/' + ? remoteDirectoryPath : + '/' + remoteDirectoryPath; + } String remoteFileMetadata = - new URI(protocol(), null, host, Integer.parseInt(port), - remoteDirectoryPath.charAt(0) == '/' - ? remoteDirectoryPath : - '/' + remoteDirectoryPath, - null, remoteFileName) + new URI(protocol(), null, host, Integer.parseInt(port), remoteDir, null, remoteFileName) .toString(); this.remoteFileMetadataStore.put(buildMetadataKey(localFile), remoteFileMetadata); }