Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-47896] SerializableOnlyOverRemoting #3980

14 changes: 7 additions & 7 deletions core/src/main/java/hudson/FilePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
import org.apache.tools.zip.ZipFile;
import org.jenkinsci.remoting.RoleChecker;
import org.jenkinsci.remoting.RoleSensitive;
import org.jenkinsci.remoting.SerializableOnlyOverRemoting;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.Function;
Expand Down Expand Up @@ -207,7 +208,7 @@
* @author Kohsuke Kawaguchi
* @see VirtualFile
*/
public final class FilePath implements Serializable {
public final class FilePath implements SerializableOnlyOverRemoting {
/**
* Maximum http redirects we will follow. This defaults to the same number as Firefox/Chrome tolerates.
*/
Expand Down Expand Up @@ -2985,18 +2986,17 @@ public boolean isRemote() {
}

private void writeObject(ObjectOutputStream oos) throws IOException {
Channel target = Channel.current();

if(channel!=null && channel!=target)
throw new IllegalStateException("Can't send a remote FilePath to a different remote channel");
Channel target = getChannelForSerialization();
if (channel != null && channel != target) {
throw new IllegalStateException("Can't send a remote FilePath to a different remote channel (current=" + channel + ", target=" + target + ")");
}

oos.defaultWriteObject();
oos.writeBoolean(channel==null);
}

private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
Channel channel = Channel.current();
assert channel!=null;
Channel channel = getChannelForSerialization();

ois.defaultReadObject();
if(ois.readBoolean()) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/hudson/model/TaskListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.Serializable;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Formatter;
import javax.annotation.Nonnull;
import org.jenkinsci.remoting.SerializableOnlyOverRemoting;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.accmod.restrictions.ProtectedExternally;
Expand Down Expand Up @@ -66,7 +66,7 @@
*
* @author Kohsuke Kawaguchi
*/
public interface TaskListener extends Serializable {
public interface TaskListener extends SerializableOnlyOverRemoting {
/**
* This writer will receive the output of the build
*/
Expand Down
10 changes: 6 additions & 4 deletions core/src/main/java/hudson/util/ProcessTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import hudson.util.ProcessTreeRemoting.IOSProcess;
import hudson.util.ProcessTreeRemoting.IProcessTree;
import jenkins.security.SlaveToMasterCallable;
import org.jenkinsci.remoting.SerializableOnlyOverRemoting;
import jenkins.util.java.JavaUtils;
import org.jvnet.winp.WinProcess;
import org.jvnet.winp.WinpException;
Expand All @@ -54,6 +55,7 @@
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.io.Serializable;
import java.io.ObjectStreamException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -95,7 +97,7 @@
* @author Kohsuke Kawaguchi
* @since 1.315
*/
public abstract class ProcessTree implements Iterable<OSProcess>, IProcessTree, Serializable {
public abstract class ProcessTree implements Iterable<OSProcess>, IProcessTree, SerializableOnlyOverRemoting {
/**
* To be filled in the constructor of the derived type.
*/
Expand Down Expand Up @@ -1828,7 +1830,7 @@ public static abstract class Local extends ProcessTree {
/**
* Represents a process tree over a channel.
*/
public static class Remote extends ProcessTree implements Serializable {
public static class Remote extends ProcessTree {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be a breaking change? I know it comes from #3144 , but I am not sure why I did that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implements Serializable clause was always redundant, given the superclass:

public abstract class ProcessTree implements Iterable<OSProcess>, IProcessTree, Serializable

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. One month without coding for me :D

private final IProcessTree proxy;

@Deprecated
Expand Down Expand Up @@ -1908,8 +1910,8 @@ public <T> T act(ProcessCallable<T> callable) throws IOException, InterruptedExc
/**
* Use {@link Remote} as the serialized form.
*/
/*package*/ Object writeReplace() {
return new Remote(this,Channel.current());
/*package*/ Object writeReplace() throws ObjectStreamException {
return new Remote(this, getChannelForSerialization());
}

// public static void main(String[] args) {
Expand Down