title: RMI UnmarshalException
body: <p>I'm currently developing a system that loads classes via rmi.  This system uses a classloader that communicates with the server in order to get the classes.  The code is as follows.</p>
  
  <p>Server:</p>
  
  <pre><code>import rocks.squareRock;
  
  import java.rmi.Naming;
  import java.rmi.RemoteException;
  import java.rmi.server.UnicastRemoteObject;
  
  public class Server extends UnicastRemoteObject
          implements RemInterface {
  
      public Server() throws RemoteException {
          super();
      }
  
      public static void main(String argv[]) {
          try {
              Server serv = new Server();
              Naming.rebind("RockServer", serv);
          } catch (Throwable t) {
              t.printStackTrace();
          }
      }
  
      public Class&lt;?&gt; getRockClass(String type) {
          if (type.equals("squareRock"))
              return squareRock.class;
          else
              return null;
      }
  }
  </code></pre>
  
  <p>Client:</p>
  
  <pre><code>import rocks.Rock;
  
  import java.net.MalformedURLException;
  import java.rmi.Naming;
  import java.rmi.NotBoundException;
  import java.rmi.RemoteException;
  
  public class Client {
      RemInterface reminterface = null;
      RockLoader rl = null;
  
      public Client() {
          String strName = "rmi://127.0.0.1/RockServer";
          try {
              reminterface = (RemInterface) Naming.lookup(strName);
              rl = new RockLoader(reminterface);
          } catch (RemoteException e) {
              e.printStackTrace();
          } catch (NotBoundException e) {
              e.printStackTrace();
          } catch (MalformedURLException e) {
              e.printStackTrace();
          }
  
          loadRock("squareRock");
  
      }
  
      public Rock loadRock(String rock) {
          try {
              return (Rock) rl.loadClass(rock, false).newInstance();
          } catch (Throwable t) {
              return null;
          }
      }
  }
  </code></pre>
  
  <p>Interface:</p>
  
  <pre><code>public interface RemInterface {
      public Class&lt;?&gt; getRockClass(String type) throws RemoteException;
  }
  </code></pre>
  
  <p>RockLoader:</p>
  
  <pre><code>import java.io.Serializable;
  
  public class RockLoader extends ClassLoader implements Serializable {
  
      private RemInterface reminterface = null;
  
      public RockLoader(RemInterface reminterface) {
          super();
          this.reminterface = reminterface;
      }
  
      @Override
      protected synchronized Class&lt;?&gt; loadClass(String className, boolean resolve)
              throws ClassNotFoundException {
          try {
              return reminterface.getRockClass(className);
          } catch (Exception e) {
              e.printStackTrace();
              return null;
          }
      }
  }
  </code></pre>
  
  <p>The error I'm getting with this is (client-side):</p>
  
  <pre><code>java.rmi.UnmarshalException: error unmarshalling return; nested exception is: 
  java.lang.ClassNotFoundException: SquareRock
  </code></pre>
  
  <p>This confuses me, as I'm not unmarshalling a SquareRock instance, but a Class.  The only thought I have is that my classloader might be wrong.</p>