NIFI-7232 if users do not supply a remote path PutSFTP with conflict resolution will fail with an NPE

This commit is contained in:
Joe Witt 2020-03-06 10:32:12 -05:00
parent 7c57e75da4
commit 20dda05f26
No known key found for this signature in database
GPG Key ID: 9093BF854F811A1A
2 changed files with 4 additions and 2 deletions

View File

@ -39,6 +39,7 @@ import org.apache.nifi.processors.standard.util.FileInfo;
import org.apache.nifi.processors.standard.util.FileTransfer;
import org.apache.nifi.processors.standard.util.SFTPTransfer;
import org.apache.nifi.util.StopWatch;
import org.apache.nifi.util.StringUtils;
/**
* Base class for PutFTP & PutSFTP
@ -102,8 +103,8 @@ public abstract class PutFileTransfer<T extends FileTransfer> extends AbstractPr
do {
final String rootPath = context.getProperty(FileTransfer.REMOTE_PATH).evaluateAttributeExpressions(flowFile).getValue();
final String workingDirPath;
if (rootPath == null) {
workingDirPath = null;
if (StringUtils.isBlank(rootPath)) {
workingDirPath = transfer.getHomeDirectory(flowFile);
} else {
workingDirPath = transfer.getAbsolutePath(flowFile, rootPath);
}

View File

@ -631,6 +631,7 @@ public class SFTPTransfer implements FileTransfer {
try {
this.homeDir = sftpClient.canonicalize("");
} catch (IOException e) {
this.homeDir = "";
// For some combination of server configuration and user home directory, getHome() can fail with "2: File not found"
// Since homeDir is only used tor SEND provenance event transit uri, this is harmless. Log and continue.
logger.debug("Failed to retrieve {} home directory due to {}", new Object[]{username, e.getMessage()});