Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-9050] Improved the error diagnostics when a remote met…
…hod call fails to deserialize.
  • Loading branch information
kohsuke committed Mar 19, 2011
1 parent ca4de00 commit 2aad402
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -90,6 +90,9 @@
<li class=rfe>
Added a new axis type to the matrix project that lets you use boolean expressions
(<a href="https://github.com/jenkinsci/jenkins/pull/66">pull request #66</a>)
<li class=rfe>
Improved the error diagnostics when a remote method call fails to deserialize.
(<a href="http://issues.jenkins-ci.org/browse/JENKINS-9050">issue 9050</a>)
</ul>
</div><!--=TRUNK-END=-->

Expand Down
4 changes: 4 additions & 0 deletions remoting/src/main/java/hudson/remoting/UserRequest.java
Expand Up @@ -98,6 +98,10 @@ protected UserResponse<RSP,EXC> perform(Channel channel) throws EXC {
o = deserialize(channel,request,cl);
} catch (ClassNotFoundException e) {
throw new ClassNotFoundException("Failed to deserialize the Callable object. Perhaps you needed to implement DelegatingCallable?",e);
} catch (RuntimeException e) {
// if the error is during deserialization, throw it in one of the types Channel.call will
// capture its call site stack trace. See
throw new Error("Failed to deserialize the Callable object.",e);
}

Callable<RSP,EXC> callable = (Callable<RSP,EXC>)o;
Expand Down
27 changes: 27 additions & 0 deletions remoting/src/test/java/hudson/remoting/ChannelTest.java
@@ -1,10 +1,37 @@
package hudson.remoting;

import org.jvnet.hudson.test.Bug;

import java.io.IOException;
import java.io.ObjectInputStream;

/**
* @author Kohsuke Kawaguchi
*/
public class ChannelTest extends RmiTestBase {
public void testCapability() {
assertTrue(channel.remoteCapability.supportsMultiClassLoaderRPC());
}

@Bug(9050)
public void testFailureInDeserialization() throws Exception {
try {
channel.call(new CallableImpl());
fail();
} catch (IOException e) {
e.printStackTrace();
assertEquals("foobar",e.getCause().getCause().getMessage());
assertTrue(e.getCause().getCause() instanceof ClassCastException);
}
}

private static class CallableImpl implements Callable<Object,IOException> {
public Object call() throws IOException {
return null;
}

private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
throw new ClassCastException("foobar");
}
}
}

0 comments on commit 2aad402

Please sign in to comment.