From 110081eeff5af8a5a8a4f7972a6bf86811ecf2f5 Mon Sep 17 00:00:00 2001 From: Gintas Grigelionis Date: Wed, 11 Apr 2018 18:40:23 +0200 Subject: [PATCH] Add null guard, refactor loop --- .../apache/tools/ant/taskdefs/optional/net/FTP.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java b/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java index 75f82c0ca..029e2d994 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java @@ -956,11 +956,10 @@ public class FTP extends Task implements FTPTaskConfig { */ private String getRelativePath(String currentPath, String currentRelativePath) { List pathElements = SelectorUtils.tokenizePath(getAbsolutePath(), remoteFileSep); - List pathElements2 = SelectorUtils.tokenizePath(currentPath, remoteFileSep); - StringBuilder relPath = new StringBuilder(currentRelativePath); - final int size = pathElements.size(); - for (int pcount = pathElements2.size(); pcount < size; pcount++) { - String currentElement = pathElements.get(pcount); + StringBuilder relPath = new StringBuilder(currentRelativePath == null + ? "" : currentRelativePath); + for (String currentElement : pathElements.subList(SelectorUtils.tokenizePath(currentPath, + remoteFileSep).size(), pathElements.size())) { FTPFile[] theFiles = listFiles(currentPath); FTPFile theFile = null; if (theFiles != null) { @@ -973,8 +972,7 @@ public class FTP extends Task implements FTPTaskConfig { // hit a hidden file assume not a symlink relPath.append(currentElement); currentPath += remoteFileSep + currentElement; - log("Hidden file " + relPath - + " assumed to not be a symlink.", + log("Hidden file " + relPath + " assumed to not be a symlink.", Project.MSG_VERBOSE); } else { traversesSymlinks = traversesSymlinks || theFile.isSymbolicLink();