Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-37566] - FindBugs: Suppress serialization warning for UserRe…
…quest#classLoaderProxy.

The field is actually always serializable, but we cannot confirm it statically due to the reflection code.
I decided to just suppress it for now and to document the method.
  • Loading branch information
oleg-nenashev committed Nov 16, 2017
1 parent 446ae85 commit 5290e26
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main/java/hudson/remoting/RemoteClassLoader.java
Expand Up @@ -712,7 +712,17 @@ public static interface IClassLoader {
ResourceFile[] getResources2(String name) throws IOException;
}

public static IClassLoader export(@Nonnull ClassLoader cl, Channel local) {
/**
* Exports classloader over the channel.
*
* If the classloader is an instance of {@link RemoteClassLoader}, this classloader will be unwrapped and reused.
* Otherwise, a classloader object will be exported
*
* @param cl Classloader to be exported
* @param local Channel
* @return Exported reference. This reference is always {@link Serializable} though interface is not explict about that
*/
public static IClassLoader export(@Nonnull ClassLoader cl, @Nonnull Channel local) {
if (cl instanceof RemoteClassLoader) {
// check if this is a remote classloader from the channel
final RemoteClassLoader rcl = (RemoteClassLoader) cl;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/hudson/remoting/UserRequest.java
Expand Up @@ -57,6 +57,7 @@ final class UserRequest<RSP,EXC extends Throwable> extends Request<UserResponse<
private final byte[] request;

@Nonnull
@SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "RemoteClassLoader.export() always returns a serializable instance, but we cannot check it statically due to the java.lang.reflect.Proxy")
private final IClassLoader classLoaderProxy;
private final String toString;
/**
Expand Down Expand Up @@ -101,6 +102,8 @@ public UserRequest(Channel local, Callable<?,EXC> c) throws IOException {
exports.stopRecording();
}

// TODO: We know that the classloader is always serializable, but there is no way to express it here in a compatible way \
// (as well as to call instance off or whatever)
this.classLoaderProxy = RemoteClassLoader.export(cl, local);
}

Expand Down

0 comments on commit 5290e26

Please sign in to comment.