-
Bug
-
Resolution: Duplicate
-
P2
-
None
-
1.2.0
-
x86
-
generic
The code below supposed to load an applet from a URL and define it. The example below uses the Animator class from the /usr/local/java jsut to demonstrate the bug. Everything goes smoothly until defineClass() is called and fails ( tried on Windows as well as with Solaris 1.1.6 and 1.1.7)
java.lang.ClassFormatError: Illegal constant pool type
import java.util.*;
import java.net.*;
import java.io.*;
import java.applet.*;
public class FarmletTender {
public FarmletTender () {
}
static public void main(String args[]) {
try {
FarmletLoader loader = new FarmletLoader();
Applet farmlet =
(Applet)loader.loadClass("Applet", true).newInstance();
System.out.println("Hello World");
Thread.sleep(10000);
} catch (Exception e) {
System.out.println("Got exception: " + e);
}
}
}
class FarmletLoader extends ClassLoader {
//String host;
//int port;
Hashtable cache = new Hashtable();
FarmletLoader() {
super();
}
private byte loadClassData(String name)[] throws IOException {
// load the class data from the connection
URL url =
new URL("file:/usr/local/java/jdk1.1.6/solaris/demo/Animator/1.1/Animator.class");
System.out.println("url is: " + url);
URLConnection link = url.openConnection();
System.out.println("length is: " + link.getContentLength());
System.out.println("type is: " + link.getContentType());
System.out.println("encoding is " + link.getContentEncoding());
System.out.println("content object is: " + link.getContent());
byte data[] = new byte[link.getContentLength()];
link.getInputStream().read(data, 0, link.getContentLength());
System.out.println(" content is: " + data[0] + data[1] + data[2]);
return data;
}
public synchronized Class loadClass(String name,
boolean resolve)
throws ClassNotFoundException {
try {
Class c = (Class)cache.get(name);
if (c == null) {
byte data[] = loadClassData(name);
System.out.println("length = " + data.length);
c = defineClass(name, data, 0, data.length);
System.out.println("here " + c);
cache.put(name, c);
System.out.println("here");
}
if (resolve)
resolveClass(c);
System.out.println("here");
return c;
} catch (Exception e) {
throw new ClassNotFoundException("Error loading class " + name
+
": " + e);
}
}
}
The output as below:
javac FarmletTender.java
java FarmletTender
url is: file:/usr/local/java/jdk1.1.6/solaris/demo/Animator/1.1/Animator.class
length is: 16323
type is: application/java-vm
encoding is null
content object is: java.io.BufferedInputStream@1dce0f0c
content is: -54-2-70
length = 16323
java.lang.ClassFormatError: Illegal constant pool type
at java.lang.ClassLoader.defineClass(ClassLoader.java)
at FarmletLoader.loadClass(FarmletTender.java:55)
at FarmletTender.main(FarmletTender.java:15)
4165059 bug is opened against JDK1.2 beta4, please note that the error message is differnet on JDK 1.2 beta4.
java.lang.ClassFormatError: Illegal constant pool type
import java.util.*;
import java.net.*;
import java.io.*;
import java.applet.*;
public class FarmletTender {
public FarmletTender () {
}
static public void main(String args[]) {
try {
FarmletLoader loader = new FarmletLoader();
Applet farmlet =
(Applet)loader.loadClass("Applet", true).newInstance();
System.out.println("Hello World");
Thread.sleep(10000);
} catch (Exception e) {
System.out.println("Got exception: " + e);
}
}
}
class FarmletLoader extends ClassLoader {
//String host;
//int port;
Hashtable cache = new Hashtable();
FarmletLoader() {
super();
}
private byte loadClassData(String name)[] throws IOException {
// load the class data from the connection
URL url =
new URL("file:/usr/local/java/jdk1.1.6/solaris/demo/Animator/1.1/Animator.class");
System.out.println("url is: " + url);
URLConnection link = url.openConnection();
System.out.println("length is: " + link.getContentLength());
System.out.println("type is: " + link.getContentType());
System.out.println("encoding is " + link.getContentEncoding());
System.out.println("content object is: " + link.getContent());
byte data[] = new byte[link.getContentLength()];
link.getInputStream().read(data, 0, link.getContentLength());
System.out.println(" content is: " + data[0] + data[1] + data[2]);
return data;
}
public synchronized Class loadClass(String name,
boolean resolve)
throws ClassNotFoundException {
try {
Class c = (Class)cache.get(name);
if (c == null) {
byte data[] = loadClassData(name);
System.out.println("length = " + data.length);
c = defineClass(name, data, 0, data.length);
System.out.println("here " + c);
cache.put(name, c);
System.out.println("here");
}
if (resolve)
resolveClass(c);
System.out.println("here");
return c;
} catch (Exception e) {
throw new ClassNotFoundException("Error loading class " + name
+
": " + e);
}
}
}
The output as below:
javac FarmletTender.java
java FarmletTender
url is: file:/usr/local/java/jdk1.1.6/solaris/demo/Animator/1.1/Animator.class
length is: 16323
type is: application/java-vm
encoding is null
content object is: java.io.BufferedInputStream@1dce0f0c
content is: -54-2-70
length = 16323
java.lang.ClassFormatError: Illegal constant pool type
at java.lang.ClassLoader.defineClass(ClassLoader.java)
at FarmletLoader.loadClass(FarmletTender.java:55)
at FarmletTender.main(FarmletTender.java:15)
4165059 bug is opened against JDK1.2 beta4, please note that the error message is differnet on JDK 1.2 beta4.
- duplicates
-
JDK-4165059 ClassFormatError: Applet (Illegal UTF8 string in constant pool) in defineClass
- Closed