Skip to content

Commit 3ef484d

Browse files
artembilanspring-builds
authored andcommitted
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 467c961)
1 parent 882685d commit 3ef484d

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ protected void rollbackFromFileToListEnd(List<F> filteredFiles, F file) {
444444
}
445445
}
446446

447-
protected boolean copyFileToLocalDirectory(String remoteDirectoryPath, // NOSONAR
447+
protected boolean copyFileToLocalDirectory(@Nullable String remoteDirectoryPath, // NOSONAR
448448
@Nullable EvaluationContext localFileEvaluationContext, F remoteFile, File localDirectory,
449449
Session<F> session) throws IOException {
450450

@@ -503,12 +503,15 @@ protected boolean copyFileToLocalDirectory(String remoteDirectoryPath, // NOSONA
503503
String host = hostPort.substring(0, colonIndex);
504504
String port = hostPort.substring(colonIndex + 1);
505505
try {
506+
String remoteDir = "/";
507+
if (remoteDirectoryPath != null) {
508+
remoteDir =
509+
remoteDirectoryPath.charAt(0) == '/'
510+
? remoteDirectoryPath :
511+
'/' + remoteDirectoryPath;
512+
}
506513
String remoteFileMetadata =
507-
new URI(protocol(), null, host, Integer.parseInt(port),
508-
remoteDirectoryPath.charAt(0) == '/'
509-
? remoteDirectoryPath :
510-
'/' + remoteDirectoryPath,
511-
null, remoteFileName)
514+
new URI(protocol(), null, host, Integer.parseInt(port), remoteDir, null, remoteFileName)
512515
.toString();
513516
this.remoteFileMetadataStore.put(buildMetadataKey(localFile), remoteFileMetadata);
514517
}

0 commit comments

Comments
 (0)