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

(spec) RMIClassLoader.loadClass() doesn't work if codebase changed dynamically



    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 1.4.0, 5.0
    • Fix Version/s: None
    • Component/s: core-libs
    • Subcomponent:
    • CPU:
      generic, sparc
    • OS:
      generic, solaris_2.6


      Name: acR10002 Date: 09/27/2001

      The same issue has been already reported in a bug 4404753 which has been
      closed as duplicate of 4417552, which, in it's turn, has been incorrectly
      closed as a duplicate of 4418673. The 4418673 is now in state INTEGRATED,
      however, the example provided in the 4404753 still fails.
      So once again the details of the issue:

      The spec for RMIClassLoader.loadClass(String) says:
      ------------ javadoc for RMIClassLoader.loadClass(String), jdk1.4.0b-80 -------
      Loads a class from the codebase URL path specified by the
      java.rmi.server.codebase property.
      However, in fact, the java.rmi.server.codebase is examined just once, at the
      first call to RMIClassLoader.loadClass() method. Any attempt to change codebase
      property after RMIClassLoader.loadClass() after first use will fail, as it is
      shown in the example below:
      ---------------- Test.java ------------
      import java.rmi.*;
      import java.rmi.server.*;
      public class Test {
          public static void main(String args[]) {
              System.setSecurityManager(new RMISecurityManager());
              Class cl = null;
              if (args.length > 1) {
                  try {
                      System.out.println("RMIClassLoader has been pre-initialized");
                  } catch (Exception e) {
              System.setProperty("java.rmi.server.codebase", args[0]);
              try {
                  cl = RMIClassLoader.loadClass("LoadMe");
              } catch (Exception e) {
                  System.out.println("Loading failed : ");
              System.out.println("Successfully loaded class : " + cl.getName());
      To reproduce the problem, please compile the following class :
      --------- LoadMe.java ----
      public class LoadMe {
      and put the .class file somewhere out of your CLASSPATH variable, for example,
      in the directory "loadme". Then, verify that the class is loadable by
      RMIClassLoader at first call of loadClass():
      --> java Test file:///home/ayc/tmp/loadme/
      Successfully loaded class : LoadMe
      And see that the class can not be loaded if loadClass() has been called once in
      the past with different code base set (or not set all):
      --> java Test file:///home/ayc/tmp/loadme/ doublecall
      RMIClassLoader has been pre-initialized
      Loading failed :
      java.lang.ClassNotFoundException: LoadMe
              at java.net.URLClassLoader$1.run(URLClassLoader.java:201)
              at java.security.AccessController.doPrivileged(Native Method)
              at java.net.URLClassLoader.findClass(URLClassLoader.java:189)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:308)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:264)
              at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:324)
              at java.lang.Class.forName0(Native Method)
              at java.lang.Class.forName(Class.java:212)
              at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:430)
              at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:164)
              at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:632)
              at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:210)
              at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:138)
              at Test.main(Test.java:26)
      The above output has been obtained under:
      java version "1.4.0-beta3"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b80)
      Java HotSpot(TM) Client VM (build 1.4.0-beta3-b80, mixed mode)
      Please don't close this bug as a duplicate of either 4404753, 4417552 or
      4418673 since all of them are either closed or integrated, but the issue is
      still unresolved.



          Issue Links



              awollratsunw Ann Wollrath (Inactive)
              aycsunw Ayc Ayc (Inactive)
              0 Vote for this issue
              0 Start watching this issue