title: Java RMI call with remote parameters fails
body: <p>I obtain a remote reference from an RMI registry; lets call it <code>s</code>. Now, <code>s</code> is of (interface) type <code>S</code> which offers a method <code>m(A, B, int)</code>.</p>
  
  <p>On the client, I have implementations of <code>A</code> and <code>B</code> which both extend <code>UnicastRemoteObject</code> (and are therefore automatically exported). Consider instances <code>a</code> and <code>b</code>, respectively.</p>
  
  <p>Now I call <code>m(a, b, 0)</code>. It compiles, but fails at runtime with the very non-informative </p>
  
  <pre><code>java.lang.IllegalArgumentException: argument type mismatch
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:597)
  at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305)
  at sun.rmi.transport.Transport$1.run(Transport.java:159)
  at java.security.AccessController.doPrivileged(Native Method)
  at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
  at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
  at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
  at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
  at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
  at java.lang.Thread.run(Thread.java:662)
  at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255)
  at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)
  at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:142)
  at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:178)
  at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:132)
  at $Proxy0.m(Unknown Source)
  [... application specific sites]
  </code></pre>
  
  <p>Sadly, <code>NativeMethodAccessorImpl.invoke0</code> is natively implemented and can not be inspected. So, I am at a total loss. Obviously, types match, otherwise the original code should not compile, right?</p>
  
  <p>What can be reasons for this?</p>
  
  <p><strong>Edit:</strong> We use Java 6. The error can be reproduced on Ubuntu 11.04 32bit, Ubuntu 10.10 64bit and Windows 7 32bit.</p>
  
  <p><strong>Edit 2:</strong> I implemented some dummy methods on S to test individual parameters. Turns out, <code>s.n()</code>, <code>s.t0(b)</code> and <code>s.t1(0)</code> work as expected; only <code>s.t2(a)</code> fails. This implies that something is wrong with how I implemented <code>A</code>, doesn't it?</p>
  
  <p>The only striking difference between <code>A</code> and <code>B</code> (aside from actual content, of course) is that <code>A</code> is a class extending <code>UnicastRemoteObject</code> and follows the convention of a remote interface but does not implement a distinguished remote interface. <code>B</code> is a remote interface an implementation of which I pass.</p>