diff --git a/core/src/main/java/hudson/FilePath.java b/core/src/main/java/hudson/FilePath.java index f532dbe9e6..e50577e431 100644 --- a/core/src/main/java/hudson/FilePath.java +++ b/core/src/main/java/hudson/FilePath.java @@ -620,10 +620,14 @@ public final class FilePath implements Serializable { * so that one can perform local file operations. */ public T act(final FileCallable callable) throws IOException, InterruptedException { + return act(callable,callable.getClass().getClassLoader()); + } + + private T act(final FileCallable callable, ClassLoader cl) throws IOException, InterruptedException { if(channel!=null) { // run this on a remote system try { - return channel.call(new FileCallableWrapper(callable)); + return channel.call(new FileCallableWrapper(callable,cl)); } catch (AbortException e) { throw e; // pass through so that the caller can catch it as AbortException } catch (IOException e) { @@ -969,7 +973,7 @@ public final class FilePath implements Serializable { return r; } - }); + }, (filter!=null?filter:this).getClass().getClassLoader()); } /** @@ -1688,9 +1692,16 @@ public final class FilePath implements Serializable { */ private class FileCallableWrapper implements DelegatingCallable { private final FileCallable callable; + private transient ClassLoader classLoader; public FileCallableWrapper(FileCallable callable) { this.callable = callable; + this.classLoader = callable.getClass().getClassLoader(); + } + + private FileCallableWrapper(FileCallable callable, ClassLoader classLoader) { + this.callable = callable; + this.classLoader = classLoader; } public T call() throws IOException { @@ -1698,7 +1709,7 @@ public final class FilePath implements Serializable { } public ClassLoader getClassLoader() { - return callable.getClass().getClassLoader(); + return classLoader; } private static final long serialVersionUID = 1L;