title: Java RMI ClassCast exception
body: <p>I am developing a distributed system using a following JAVA RMI setup.</p>
  
  <pre><code>public interface NodeOperations {
   /* RMI methods */
   public FingerTable getFingerTable() throws RMIException;
  }
  
  public class Node implements NodeOperations {
   /* Implements all RMI methods */
   /* Also holds a object of FingerTable */
   FingerTable ft;
  
  }
  
  public class FingerTable {
   /* Holds a reference to Node class which has object of 'this' FingerTable */
   Node self;
  }
  </code></pre>
  
  <p>All RMI communication is done via methods present in <code>NodeOperations</code> interface. There is one method which returns <code>FingerTable</code> object for a particular node. However I am getting below exception when I call that method from the client. How do I solve this issue?</p>
  
  <pre><code>java.lang.ClassCastException: cannot assign instance of com.sun.proxy.$Proxy5 to field chord.FingerTable.self of type chord.Node in instance of chord.FingerTable
      at java.io.ObjectStreamClass$FieldReflector.setObjFieldValues(ObjectStreamClass.java:2133)
      at java.io.ObjectStreamClass.setObjFieldValues(ObjectStreamClass.java:1305)
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2237)
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2155)
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2013)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535)
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2231)
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2155)
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2013)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:422)
      at sun.rmi.server.UnicastRef.unmarshalValue(UnicastRef.java:326)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:175)
      at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:227)
      at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:179)
      at com.sun.proxy.$Proxy5.getNodeInfo(Unknown Source)
      at chord.NodeTest.testTopology(NodeTest.java:108)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  </code></pre>