Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4353431

RMI java.lang.ClassNotFoundException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.2.2
    • core-libs
    • x86
    • windows_nt



      Name: jk109818 Date: 07/14/2000


      java version "1.2.2"
      Classic VM (build JDK-1.2.2_005, native threads, symcjit)


      I am trying to get a simple distributed program to work using RMI. I am
      seeing the following exception on the client side while trying to make a
      remote call:

      RMIClient exception: RemoteException occurred in server thread; nested
      exception is:
              java.rmi.UnmarshalException: error unmarshalling arguments; nested
      exception is:
              java.lang.ClassNotFoundException: [Ljava.lang.Object;
      java.rmi.ServerException: RemoteException occurred in server thread; nested
      exception is:
              java.rmi.UnmarshalException: error unmarshalling arguments; nested
      exception is:
              java.lang.ClassNotFoundException: [Ljava.lang.Object;
      java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
              java.lang.ClassNotFoundException: [Ljava.lang.Object;
      java.lang.ClassNotFoundException: [Ljava.lang.Object;
              at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer
      (StreamRemoteCall.java:249)
              at sun.rmi.transport.StreamRemoteCall.executeCall
      (StreamRemoteCall.java:224)
              at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:126)
              at sample.rmiserver.RMIServer_Stub.queueTask(Unknown Source)
              at sample.rmiclient.RMIClient.run(RMIClient.java:24)

      The offending line of code is in the constructor of the class (i.e.,
      Task.java) that I am passing to the remote object's method (i.e.,
      queueTask()).

      This exception, however, is thrown sporadically, at best. If I run the
      client repeatedly, it will succeed 1 out of 7 (or 8) times, while the other
      6 throw the above exception. I have even tried looping within the client,
      while sleeping for a set interval, to no avail. I did find a "magic"
      interval of > 43 seconds, by which I mean if I sleep for 44 seconds or
      more, the call will succeed every time. This, of course, will not do. If,
      however, I comment out the assignment of a new Vector in the Task
      constructor, the code never throws the exception.

      I have no clue as to why the exception occurs. I have looked through every
      forum, newsgroups, developer sites that I can think of and NO ONE seems to
      have come across an intermittent exception like this. In fact, as far as I
      can tell, no one else has had any ClassNotFoundExceptions for any files
      other than the stubs.

      It has to do with java.util.Vector somehow. I also tried an array of
      serializable objects with the same results. None of the members of Task
      seem to throw this exception in the constructor, only Vector and array. I
      also tried initializing it in the declaration, same problem.

      Could someone please take the following code and try to reproduce the error
      I am seeing?

      Thank you in advance for your help.

      Sincerely,
      Ivan



      ///////////////////////////////////////////////////////////////////////////
      // The Compiler.
      ///////////////////////////////////////////////////////////////////////////
      java version "1.2.2"
      Classic VM (build JDK-1.2.2_005, native threads, symcjit)


      ///////////////////////////////////////////////////////////////////////////
      // The Server Operating System.
      ///////////////////////////////////////////////////////////////////////////
      Microsoft Windows NT
      version 4.00.1381


      ///////////////////////////////////////////////////////////////////////////
      // The Client Operating System.
      ///////////////////////////////////////////////////////////////////////////
      Microsoft Windows 2000 [Version 5.00.2195]



      ///////////////////////////////////////////////////////////////////////////
      //
      // The Client Files.
      //
      ///////////////////////////////////////////////////////////////////////////

      ***************************************************************************
      * Client java.policy.
      ***************************************************************************
      grant {
        permission java.net.SocketPermission "*:1024-65535", "connect,resolve";
      };


      ***************************************************************************
      * RMIClient.java.
      *
      * This file extends Thread and calls the methods of the remote object in
      * its run() method.
      *
      ***************************************************************************
      package sample.rmiclient;

      import java.rmi.*;

      import sample.rmiserver.TaskManager;
      import sample.rmiserver.Task;
      import java.util.Vector;

      public class RMIClient extends Thread {
         private String m_strName = null;

         public RMIClient ( String p_strIP ) {
            this.m_strName = "//" + p_strIP + "/TaskManager";
            this.start();
         }

         public void run() {
            if ( System.getSecurityManager() == null ) {
               System.setSecurityManager( new RMISecurityManager() );
            }
            try {
               TaskManager tMgr = ( TaskManager ) Naming.lookup( this.m_strName );

               System.out.println( "tMgr.queueTask( new Task() ) returned " +
                                   tMgr.queueTask( new Task() ) );
               System.out.println( "tMgr.deleteTask(178) returned " +
                                   tMgr.deleteTask(178) );
               System.out.println( "tMgr.getTasks() returned " +
                                   tMgr.getTasks( "allTasks" ).size() +
                                   " reports." );

            } catch ( Exception e ) {
               System.err.println( "RMIClient exception: " + e.getMessage() );
               e.printStackTrace();
            }
         }
      }


      ***************************************************************************
      * TestRMIClient.java.
      *
      * This file instantiates the RMIClient thread, passing it the IP Address of
      * the RMI server.
      *
      ***************************************************************************
      package sample.rmiclient;

      public class TestRMIClient {
         public static void main( String args[] ) {
            if ( args.length != 1 ) {
               System.err.println( "Syntax Error! Correct usage:\n" +
                          " java ComputeReport [RMI Server IP Address]\n" );
            }

            RMIClient rmic = new RMIClient( args[0] );
         }
      }





      ///////////////////////////////////////////////////////////////////////////
      //
      // The Server Files.
      //
      ///////////////////////////////////////////////////////////////////////////

      ***************************************************************************
      * The Server java.policy (located in lib).
      ***************************************************************************
      grant {
        permission java.net.SocketPermission "*:1024-65535", "connect,accept";
        permission java.io.FilePermission "C:\\Code\\lib\\-", "read";
        permission
      java.io.FilePermission "C:\\inetpub\\wwwroot\\public_dirs\\tasks", "read";
        permission java.io.FilePermission "C:\\inetpub\\wwwroot\\public_dirs\\tasks\\-
      ", "read,write,delete";
      };


      ***************************************************************************
      * TaskManager.java.
      ***************************************************************************
      package sample.rmiserver;

      import java.util.Vector;

      import java.rmi.Remote;
      import java.rmi.RemoteException;

      public interface TaskManager extends Remote {
         public int queueTask( Task p_oTask ) throws java.rmi.RemoteException;
         public boolean deleteTask( int p_intId ) throws java.rmi.RemoteException;
         public Vector getTasks( String p_str ) throws java.rmi.RemoteException;
      }


      ***************************************************************************
      * RMIServer.java.
      ***************************************************************************
      package sample.rmiserver;

      import java.util.Vector;

      import java.rmi.*;
      import java.rmi.server.*;
      import java.net.*;

      public class RMIServer
         extends java.rmi.server.UnicastRemoteObject
         implements TaskManager
      {
         private static RMIServer m_rmiServer = null;

         public RMIServer() throws java.rmi.RemoteException {
            super();
         }

         public static synchronized RMIServer getInstance() {
            if ( m_rmiServer == null ) {
               try {
                  m_rmiServer = new RMIServer();

               } catch ( java.rmi.RemoteException re ) {
                  m_rmiServer = null;
               }
            }
            return m_rmiServer;
         }

         public int queueTask( Task p_oTask ) {
            // Queue the task here...
            return 0;
         }

         public boolean deleteTask( int p_intId ) {
            // Delete the task here...
            return true;
         }

         public Vector getTasks( String p_str ) {
            // Retrieve the tasks here...
            return new Vector();
         }

         public static void main( String[] args ) throws java.lang.Exception {
            if ( System.getSecurityManager() == null ) {
               System.setSecurityManager( new RMISecurityManager() );
            }

            TaskManager rmiServer = RMIServer.getInstance();
            String name = "//" + args[0] + "/TaskManager";
            Naming.rebind( name, rmiServer );
            System.out.println( "RMIServer bound and ready for client requests..." );
         }
      }


      ***************************************************************************
      * Task.java
      ***************************************************************************
      package sample.rmiserver;

      import java.util.Date;
      import java.util.Hashtable;
      import java.util.Vector;
      import java.util.Enumeration;

      public class Task implements java.io.Serializable {
         private java.util.Vector m_vctr = null;
         private java.util.Hashtable m_hshTable = null;
         private int m_int = 0;
         private String m_str = null;
         private java.util.Date m_dtm = null;

         public Task() {
      //If this line is commented, the exception is never thrown.
      //If left uncommented, the exception is thrown sporadically (or within a
      //certain, mysterious, "black box" timeout interval)
            this.m_vctr = new java.util.Vector();
            this.m_hshTable = new Hashtable();
            this.m_str = new String( "" );
            this.m_dtm = new java.util.Date();
            this.m_dtm.setTime( this.m_dtm.getTime() );
         }

         public java.util.Vector getVector() { return this.m_vctr; }
         public java.util.Hashtable getHashtable() { return this.m_hshTable; }
         public int getInt() { return this.m_int; }
         public String getString() { return this.m_str; }
         public java.util.Date getDate() { return this.m_dtm; }

         public void setVector( java.util.Vector p_vctr ) { this.m_vctr =
      p_vctr; }
         public void setHashtable( java.util.Hashtable p_hshTable ) { this.m_hshTable
      = p_hshTable; }
         public void setInt( int p_int ) { this.m_int =
      p_int; }
         public void setString( String p_str ) { this.m_str =
      p_str; }
         public void setDate( java.util.Date p_dtm ) { this.m_dtm =
      p_dtm; }
         public void addVectorElement( String p_elem ) { this.m_vctr.add
      ( p_elem ); }
      }





      ///////////////////////////////////////////////////////////////////////////
      //
      // The build.
      //
      // Starting from the client machine (drive M) will proceed to do the following:
      //
      ///////////////////////////////////////////////////////////////////////////

      ***************************************************************************
      * Set the classpath.
      ***************************************************************************
      SET CLASSPATH=M:\;M:\code;

      ***************************************************************************
      * Remove the old class files (redundant)
      ***************************************************************************
      DEL M:\code\sample\rmiserver\*.class
      DEL M:\code\sample\rmiclient\*.class

      ***************************************************************************
      * Remove the old server jar file (redundant)
      ***************************************************************************
      DEL L:\Code\lib\serverCode.jar

      ***************************************************************************
      * Compile the server and client code
      ***************************************************************************
      javac M:\code\sample\rmiserver\*.java
      javac M:\code\sample\rmiclient\*.java

      ***************************************************************************
      * Create the stubs to the server code
      ***************************************************************************
      rmic -d M:\code sample.rmiserver.RMIServer

      ***************************************************************************
      * Jar the server code and stubs for use on the server.
      ***************************************************************************
      PUSHD M:\codejar cvf M:\code\sample\lib\serverCode.jar sample\rmiserver\RMIServer*.class
      jar uvf M:\code\sample\lib\serverCode.jar sample\rmiserver\TaskManager.class
      jar uvf M:\code\sample\lib\serverCode.jar sample\rmiserver\Task.class
      POPD

      ***************************************************************************
      * Copy the serverCode jar file to the server.
      ***************************************************************************
      COPY M:\code\sample\lib\serverCode.jar L:\Code\lib





      ///////////////////////////////////////////////////////////////////////////
      //
      // Starting the server.
      //
      ///////////////////////////////////////////////////////////////////////////

      ***************************************************************************
      * Change directory to lib (could just set path and leave it at that)
      ***************************************************************************
      CD C:\Code\lib

      ***************************************************************************
      * Set classpath
      ***************************************************************************
      SET CLASSPATH=.;C:\Code\lib\serverCode.jar;

      ***************************************************************************
      * Start rmiregistry, specifying 1099 as the port on which to listen.
      ***************************************************************************
      START rmiregistry 1099

      ***************************************************************************
      * Start RMIServer, specifying 1099 as the port on which to bind.
      ***************************************************************************
      java -Djava.rmi.server.codebase=file:///c:\Code\lib\-/
           -Djava.rmi.server.hostname=<<<server host name>>>
           -Djava.security.policy=C:\Code\lib\java.policy
           sample.rmiserver.RMIServer <<<server IP address>>> 1099





      ///////////////////////////////////////////////////////////////////////////
      //
      // Starting the client.
      //
      ///////////////////////////////////////////////////////////////////////////

      ***************************************************************************
      * Start TestRMIClient, specifying the server's IP Address.
      ***************************************************************************
      java -Djava.rmi.server.codebase=file:///M:\code\-/
           -Djava.security.policy=java.policy
           sample.rmiclient.TestRMIClient <<<server IP Address>>>
      (Review ID: 106735)
      ======================================================================

            peterjones Peter Jones (Inactive)
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: