Skip to content
Permalink
Browse files

Merge pull request #2914 from jglick/FilePath.list

[JENKINS-44942] - FilePath.list() & .listDirectories() null safety
  • Loading branch information...
oleg-nenashev committed Jun 16, 2017
2 parents 70f80e9 + 064bdbb commit a5dc255d2150d0d34eec918c4c45794a66663f7d
Showing with 11 additions and 4 deletions.
  1. +11 −1 core/src/main/java/hudson/FilePath.java
  2. +0 −3 core/src/main/java/jenkins/util/VirtualFile.java
@@ -127,6 +127,7 @@
import static hudson.Util.deleteFile;
import static hudson.Util.fixEmpty;
import static hudson.Util.isSymlink;
import java.util.Collections;

/**
* {@link File} like object with remoting support.
@@ -1636,6 +1637,7 @@ public Integer invoke(File f, VirtualChannel channel) throws IOException {
* <p>
* This method returns direct children of the directory denoted by the 'this' object.
*/
@Nonnull
public List<FilePath> list() throws IOException, InterruptedException {
return list((FileFilter)null);
}
@@ -1645,6 +1647,7 @@ public Integer invoke(File f, VirtualChannel channel) throws IOException {
*
* @return can be empty but never null. Doesn't contain "." and ".."
*/
@Nonnull
public List<FilePath> listDirectories() throws IOException, InterruptedException {
return list(new DirectoryFilter());
}
@@ -1665,6 +1668,7 @@ public boolean accept(File f) {
* If this {@link FilePath} represents a remote path,
* the filter object will be executed on the remote machine.
*/
@Nonnull
public List<FilePath> list(final FileFilter filter) throws IOException, InterruptedException {
if (filter != null && !(filter instanceof Serializable)) {
throw new IllegalArgumentException("Non-serializable filter of " + filter.getClass());
@@ -1673,7 +1677,9 @@ public boolean accept(File f) {
private static final long serialVersionUID = 1L;
public List<FilePath> invoke(File f, VirtualChannel channel) throws IOException {
File[] children = reading(f).listFiles(filter);
if(children ==null) return null;
if (children == null) {
return Collections.emptyList();
}

ArrayList<FilePath> r = new ArrayList<FilePath>(children.length);
for (File child : children)
@@ -1692,6 +1698,7 @@ public boolean accept(File f) {
* @return
* can be empty but always non-null.
*/
@Nonnull
public FilePath[] list(final String includes) throws IOException, InterruptedException {
return list(includes, null);
}
@@ -1706,6 +1713,7 @@ public boolean accept(File f) {
* can be empty but always non-null.
* @since 1.407
*/
@Nonnull
public FilePath[] list(final String includes, final String excludes) throws IOException, InterruptedException {
return list(includes, excludes, true);
}
@@ -1721,6 +1729,7 @@ public boolean accept(File f) {
* can be empty but always non-null.
* @since 1.465
*/
@Nonnull
public FilePath[] list(final String includes, final String excludes, final boolean defaultExcludes) throws IOException, InterruptedException {
return act(new SecureFileCallable<FilePath[]>() {
private static final long serialVersionUID = 1L;
@@ -1742,6 +1751,7 @@ public boolean accept(File f) {
* @return
* A set of relative file names from the base directory.
*/
@Nonnull
private static String[] glob(File dir, String includes, String excludes, boolean defaultExcludes) throws IOException {
if(isAbsolute(includes))
throw new IOException("Expecting Ant GLOB pattern, but saw '"+includes+"'. See http://ant.apache.org/manual/Types/fileset.html for syntax");
@@ -365,9 +365,6 @@ public static VirtualFile forFilePath(final FilePath f) {
@Override public VirtualFile[] list() throws IOException {
try {
List<FilePath> kids = f.list();
if (kids == null) {
return new VirtualFile[0];
}
VirtualFile[] vfs = new VirtualFile[kids.size()];
for (int i = 0; i < vfs.length; i++) {
vfs[i] = forFilePath(kids.get(i));

0 comments on commit a5dc255

Please sign in to comment.
You can’t perform that action at this time.