-
Bug
-
Resolution: Cannot Reproduce
-
P2
-
None
-
1.3.0
-
sparc
-
solaris_7
Name: dkC59003 Date: 08/10/99
The following programm shows that invocation of ClassLoader.defineClass(byte[], int, int);
throws NullPointerException being started on JDK1.3M (HotSpot). The same program
works fine on JDK1.3L.
This bug causes failure of the following JCK tests:
vm/constantpool/arrayClasses/arrayClasses003/arrayClasses00302/arrayClasses00302.html
vm/concepts/execution/execution061/execution06102/execution06102.html
These tests are present in previous JCK version (JCK1.2a), so there is an incompatibility
between JDK versions.
----------------------------------- output ------------------------------------
novo73% java -version
Warning: JIT compiler "sunwjit" not found. Will use interpreter.
java version "1.3"
Classic VM (build JDK-1.3-L, green threads, nojit)
novo73% java test
Warning: JIT compiler "sunwjit" not found. Will use interpreter.
The array size is 545
Ok
novo73% java -version
java version "1.3beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3beta-M)
HotSpot Core VM (build 1.3beta-b-release, 1.3beta-b-release, interpreted mode,
release build b)
novo73% java test
The array size is 545
Unexpected exception java.lang.NullPointerException
---------------------------------- test.java ----------------------------------
import java.io.*;
public class test {
public static void main(String argv[]) {
try {
new TestLoader().loadClass("test");
} catch (java.lang.Throwable e) {
System.out.println(e);
return;
}
}
}
//===========================================================//
class TestLoader extends ClassLoader {
public synchronized Class loadClass(String name) throws ClassNotFoundException {
Class c = findLoadedClass(name);
if(c != null)
return c;
if(name.equals("test")) {
byte data[] = getByteArray(name);
try {
System.out.println("The array size is " + data.length);
c = defineClass(data, 0, data.length);
System.out.println("Ok");
return c;
} catch(Throwable e) {
System.out.println("Unexpected exception " + e);
}
}
return Class.forName(name, true, TestLoader.class.getClassLoader());
}
private byte[] getByteArray(String name) throws ClassNotFoundException {
String cname = name.replace('.', '/') + ".class";
InputStream in = getResourceAsStream(cname);
if (in == null) {
throw new ClassNotFoundException(name);
}
int len = 0;
byte data[];
try {
int size = 1000;
data = new byte[size];
for(int i=0;;) {
i = in.read(data, len, size-len);
if(i == -1)
break;
len += i;
if(len == size) {
byte buf[] = new byte[size*2];
System.arraycopy(data, 0, buf, 0, size);
size *= 2;
data = buf;
}
}
} catch (IOException e) {
throw new ClassNotFoundException(name, e);
} finally {
try {
in.close();
} catch (IOException e) {
throw new ClassNotFoundException(name, e);
}
}
byte buf[] = new byte[len];
System.arraycopy(data, 0, buf, 0, len);
return buf;
}
}
======================================================================
======================================================================