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] - Introduce SerializableOnlyOverRemoting in classes. #3144

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 @@ -129,6 +129,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.Stapler;
Expand Down Expand Up @@ -205,7 +206,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) {
jglick marked this conversation as resolved.
Show resolved Hide resolved
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
10 changes: 6 additions & 4 deletions core/src/main/java/hudson/cli/CliManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
import org.acegisecurity.Authentication;
import org.acegisecurity.context.SecurityContext;
import org.acegisecurity.context.SecurityContextHolder;
import org.jenkinsci.remoting.SerializableOnlyOverRemoting;

import java.io.InputStream;
import java.io.ObjectStreamException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.Serializable;
Expand All @@ -47,7 +49,7 @@
* @deprecated Specific to Remoting-based protocol.
*/
@Deprecated
public class CliManagerImpl implements CliEntryPoint, Serializable {
public class CliManagerImpl implements CliEntryPoint, SerializableOnlyOverRemoting {
Copy link
Member

Choose a reason for hiding this comment

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

Do not bother, will just conflict with #3838.

private transient final Channel channel;

private Authentication transportAuth;
Expand Down Expand Up @@ -87,7 +89,7 @@ public int main(List<String> args, Locale locale, InputStream stdin, OutputStrea
String subCmd = args.get(0);
CLICommand cmd = CLICommand.clone(subCmd);
if(cmd!=null) {
cmd.channel = Channel.current();
cmd.channel = Channel.currentOrFail();
final CLICommand old = CLICommand.setCurrent(cmd);
try {
transportAuth = Channel.currentOrFail().getProperty(CLICommand.TRANSPORT_AUTHENTICATION);
Expand Down Expand Up @@ -126,8 +128,8 @@ public int protocolVersion() {
return VERSION;
}

private Object writeReplace() {
return Channel.current().export(CliEntryPoint.class,this);
private Object writeReplace() throws ObjectStreamException {
return getChannelForSerialization().export(CliEntryPoint.class,this);
}

private static final Logger LOGGER = Logger.getLogger(CliManagerImpl.class.getName());
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 @@ -94,7 +96,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 {
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
4 changes: 3 additions & 1 deletion core/src/main/java/hudson/util/StreamTaskListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import java.nio.file.StandardOpenOption;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.jenkinsci.remoting.SerializableOnlyOverRemoting;
import org.kohsuke.stapler.framework.io.WriterOutputStream;

import javax.annotation.CheckForNull;
Expand All @@ -58,7 +60,7 @@
*
* @author Kohsuke Kawaguchi
*/
public class StreamTaskListener extends AbstractTaskListener implements TaskListener, Closeable {
public class StreamTaskListener extends AbstractTaskListener implements TaskListener, SerializableOnlyOverRemoting, Closeable {
Copy link
Member

Choose a reason for hiding this comment

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

I would expect this to be marked on TaskListener, not StreamTaskListener.

@Nonnull
private PrintStream out;
@CheckForNull
Expand Down