Class file generated by "gcj -C" throws ClassFormatError
Weiqi Gao
weiqigao@yahoo.com
Fri Jun 22 12:13:00 GMT 2001
Tom Tromey wrote:
>> >>>>> ">" == Weiqi Gao <weiqigao@yahoo.com> writes:
> >>
> >> // foo.java
> >> class foo {
> >> static long x;
> >> public static void main(String[] args) {
> >> new foo();
> >> }
> >> }
I posted the good file rather than the bad file :( .
The one that causes the error has an initializer for
x.
> I didn't try this on Solaris.
> I tried it on my x86 Linux box with JDK 1.2.2.
> It worked fine.
>> I also looked at the generated bytecode, and it
> looks reasonable.
> Could send the output of `jcf-dump -c foo'?
> That will let us see if the problem is with gcj or
> with Sun's java.
I have attached jcf-dump's for the two classes
generated from:
class foo {
static long x = 255;
public static void main(String[] args) {
}
}
and
class bar {
static long x = 255L;
public static void main(String[] args) {
}
}
foo is the bad one, bar is the good one. I have also
included the stacktrace of running 'java foo' with JDK
1.2.2 on Solaris. I get the same stack trace if I
copy foo.class to a NT box and run it with JDK 1.3.
=====
Weiqi Gao
weiqigao@yahoo.com
__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/
bar.jcf-dump
foo.jcf-dump
foo.stack-trace
-------------- next part --------------
Reading .class from ./bar.class.
Magic number: 0xcafebabe, minor_version: 3, major_version: 45.
Constant pool (count: 19):
#1: Utf8: "bar"
#2: Class name: 1="bar"
#3: Utf8: "java/lang/Object"
#4: Class name: 3="java/lang/Object"
#5: Utf8: "x"
#6: Utf8: "J"
#7: Utf8: "ConstantValue"
#8: Long 255=0xff
#10: Utf8: "main"
#11: Utf8: "([Ljava/lang/String;)V"
#12: Utf8: "Code"
#13: Utf8: "<init>"
#14: Utf8: "()V"
#15: NameAndType name: 13=<init>, signature: 14=()void
#16: Methodref class: 4=java.lang.Object name_and_type: 15=<<init> ()void>
#17: Utf8: "SourceFile"
#18: Utf8: "bar.java"
Access flags: 0x20 super
This class: 2=bar, super: 4=java.lang.Object
Interfaces (count: 0):
Fields (count: 1):
Field name:"x" static Signature: 6=long
Attribute "ConstantValue", length:2, value: #8=<Long 255>
Methods (count: 2):
Method name:"main" public static Signature: 11=(java.lang.String[])void
Attribute "Code", length:13, max_stack:0, max_locals:1, code_length:1
0: return
Method name:"<init>" Signature: 14=()void
Attribute "Code", length:17, max_stack:1, max_locals:1, code_length:5
0: aload_0
1: invokespecial #16=<Method java.lang.Object.<init> ()void>
4: return
Attributes (count: 1):
Attribute "SourceFile", length:2, #18="bar.java"
-------------- next part --------------
Reading .class from ./foo.class.
Magic number: 0xcafebabe, minor_version: 3, major_version: 45.
Constant pool (count: 18):
#1: Utf8: "foo"
#2: Class name: 1="foo"
#3: Utf8: "java/lang/Object"
#4: Class name: 3="java/lang/Object"
#5: Utf8: "x"
#6: Utf8: "J"
#7: Utf8: "ConstantValue"
#8: Integer 255=0xff
#9: Utf8: "main"
#10: Utf8: "([Ljava/lang/String;)V"
#11: Utf8: "Code"
#12: Utf8: "<init>"
#13: Utf8: "()V"
#14: NameAndType name: 12=<init>, signature: 13=()void
#15: Methodref class: 4=java.lang.Object name_and_type: 14=<<init> ()void>
#16: Utf8: "SourceFile"
#17: Utf8: "foo.java"
Access flags: 0x20 super
This class: 2=foo, super: 4=java.lang.Object
Interfaces (count: 0):
Fields (count: 1):
Field name:"x" static Signature: 6=long
Attribute "ConstantValue", length:2, value: #8=<Integer 255>
Methods (count: 2):
Method name:"main" public static Signature: 10=(java.lang.String[])void
Attribute "Code", length:13, max_stack:0, max_locals:1, code_length:1
0: return
Method name:"<init>" Signature: 13=()void
Attribute "Code", length:17, max_stack:1, max_locals:1, code_length:5
0: aload_0
1: invokespecial #15=<Method java.lang.Object.<init> ()void>
4: return
Attributes (count: 1):
Attribute "SourceFile", length:2, #17="foo.java"
-------------- next part --------------
Exception in thread "main" java.lang.ClassFormatError: foo (Bad index into constant pool)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:477)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:101)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:247)
at java.net.URLClassLoader.access1ドル(URLClassLoader.java:213)
at java.net.URLClassLoader1ドル.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:290)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
More information about the Java
mailing list