-
Bug
-
Resolution: Won't Fix
-
P3
-
None
-
1.2.0
-
sparc
-
solaris_2.5
Name: szC45993 Date: 02/11/98
The new jvm spec says (and it does not contradict to the old spec):
5.4.2 Loading Using a User-defined Class Loader, pp. 150-151:
"When the loadClass method of the class Loader L is invoked with the name N of a class or interface C to be loaded, L must perform one of the following three operations in order to load C:
...
- The class loader L can also invoke the method findSystemClass(N) on itself. Invoking this method causes class loader L to delegate the loading of class C to the default class loader."
However, the JCK ClassInterf03001.html and ClassInterf03201.html tests show
that sometimes findSystemClass method works incorrectly in jdk1.2b3F.
See log and example below. Need to note that Class.forName works fine in
same time, see clss1.java.
LOG:
novo7% setenv CLASSPATH /export/ld32/sqe/harness_release/classes:.
novo7% /export/ld14/java/dest/jdk1.2b3F/solaris/bin/javac clss1.java
Note: clss1.java uses or overrides a deprecated API. Recompile with "-deprecation" for details.
1 warning
novo7% /export/ld14/java/dest/jdk1.2b3F/solaris/bin/java clss1
********clss1.run*********
( ###loadClass: pack.clss2
( ***findSystemClass: pack.clss2
java.lang.ClassNotFoundException: pack/clss2
java.lang.NullPointerException
********clss2.run*********
ERROR: Invoking findSystemClass method causes the Java Virtual Machine to rise an exception for the loading of the existing class!
novo7%
The test works fine till jdk1.2b3F:
novo7% /export/ld14/java/dest/jdk1.2b3E/solaris/bin/java clss1
********clss1.run*********
( ###loadClass: pack.clss2
( ***findSystemClass: pack.clss2
) ***findSystemClass: pack.clss2
) ###loadClass: pack.clss2
********clss2.run*********
Okay!
SOURCES:
--------------------- clss2.java
package pack;
public class clss2 implements Runnable{
public void run() {
System.out.println("********clss2.run*********");
}
}
--------------------- clss1.java
import java.io.PrintStream;
import java.util.*;
class myClassLoader extends java.lang.ClassLoader {
static Hashtable cache = new Hashtable();
private byte loadClassData(String name)[] {
byte bt[] = null;
clss1.o.println("( %%%loadClassData: "+name);
clss1.o.println(") %%%loadClassData: "+name);
return bt;
}
public synchronized Class loadClass(String name, boolean resolve) {
Class c = (Class) cache.get(name);
String s1 = "Intr_mdt";
String s4 = "Runnable";
String name1;
clss1.o.println("( ###loadClass: "+name);
clss1.loadedname = clss1.loadedname.concat("#loadClass enter: ");
clss1.loadedname = clss1.loadedname.concat(name);
clss1.loadedname = clss1.loadedname.concat("#");
if (name.indexOf(s1) != -1) {
name1 = s1;
} else {
name1 = name;
}
if (name1.indexOf(".") != -1) {
if (c == null) {
try{
clss1.o.println("( ***findSystemClass: "+name);
clss1.loadedname = clss1.loadedname.concat("#findSystemClass enter: ");
clss1.loadedname = clss1.loadedname.concat(name);
clss1.loadedname = clss1.loadedname.concat("#");
c = findSystemClass(name1);
clss1.loadedname = clss1.loadedname.concat("#findSystemClass exit: ");
clss1.loadedname = clss1.loadedname.concat(name);
clss1.loadedname = clss1.loadedname.concat("#");
clss1.o.println(") ***findSystemClass: "+name);
}
catch (java.lang.ClassNotFoundException e) {
clss1.o.println(e);
return null;
};
cache.put(name, c);
}
} else {
if (c == null) {
byte data[] = loadClassData(name1);
clss1.o.println("( &&&defineClass: "+name);
clss1.loadedname = clss1.loadedname.concat("#defineClass enter: ");
clss1.loadedname = clss1.loadedname.concat(name);
clss1.loadedname = clss1.loadedname.concat("#");
c = defineClass(data,0,data.length);
clss1.loadedname = clss1.loadedname.concat("#defineClass exit: ");
clss1.loadedname = clss1.loadedname.concat(name);
clss1.loadedname = clss1.loadedname.concat("#");
clss1.o.println(") &&&defineClass: "+name);
cache.put(name, c);
}
}
if (resolve) {
clss1.loadedname = clss1.loadedname.concat("#resolveClass enter: ");
clss1.loadedname = clss1.loadedname.concat(name);
clss1.loadedname = clss1.loadedname.concat("#");
resolveClass(c);
clss1.loadedname = clss1.loadedname.concat("#resolveClass exit: ");
clss1.loadedname = clss1.loadedname.concat(name);
clss1.loadedname = clss1.loadedname.concat("#");
}
clss1.loadedname = clss1.loadedname.concat("#loadClass exit: ");
clss1.loadedname = clss1.loadedname.concat(name);
clss1.loadedname = clss1.loadedname.concat("#");
clss1.o.println(") ###loadClass: "+name);
return c;
}
}
public class clss1 {
public static String loadedname = "";
public static PrintStream o;
public static int run(String argv[], PrintStream out) {
myClassLoader mcl = new myClassLoader();
Class cl1 = null;
o = out;
try{
out.println("********clss1.run*********");
((Runnable)(cl1 = mcl.loadClass("pack.clss2", false)).newInstance()).run();
}
catch (java.lang.NoClassDefFoundError e) {
out.println(e);
return 2;
} catch (SecurityException e) {
out.println(e);
out.println("Could not setup test.");
return 0;
}
catch (java.lang.Throwable e) {
out.println(e);
loadedname =loadedname.concat("#Exception#");
try{
((Runnable)(Class.forName("pack.clss2")).newInstance()).run();
} catch (IllegalAccessException ee) {
out.println("forName= "+ee);
return 2;
} catch (ClassNotFoundException ee) {
out.println("forName= "+ee);
return 2;
} catch (InstantiationException ee) {
out.println("forName= "+ee);
return 2;
}
};
if (loadedname.indexOf("#findSystemClass enter: pack.clss2##Exception#") != -1) {
out.println("ERROR: Invoking findSystemClass method causes the Java Virtual Machine to rise an exception for the loading of the existing class!");
return 2;
}
if (loadedname.indexOf("#findSystemClass enter: pack.clss2#") != -1) {
out.println("Okay!");
return 0;
}
return 2;
}
public static void main(String argv[]) {
System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
}
}
---------------------
Hook 5(hook5): test
======================================================================
Name: szC45993 Date: 02/11/98
Sorry, I omitted one line from LOG.
So, the line
novo7% /export/ld14/java/dest/jdk1.2b3F/solaris/bin/javac -d . clss2.java
must be after the line
novo7% setenv CLASSPATH /export/ld32/sqe/harness_release/classes:.
======================================================================