You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bcel-user@jakarta.apache.org by Andrew Cornwall <an...@gmail.com> on 2007/10/04 02:01:19 UTC
Having trouble with example in the manual
I'm trying to get the example in the manual running. The first thing I
noticed was:
mg.addExceptionHandler(try_start, try_end, handler, "
java.io.IOException");
which under 5.2 doesn't seem to work. I replaced that with:
mg.addExceptionHandler(try_start, try_end, handler, new ObjectType("
java.io.IOException"));
After doing this, I get a .class file - but when I try to run the class
under JDK 1.5, I see:
Exception in thread "main" java.lang.ClassFormatError: Illegal exception
table range in class file HelloWorld
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(
SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
javap lists the exception table as being from 20 to 36 target 36 - which
looks valid to me:
20: getstatic #27; //Field
java/lang/System.out:Ljava/io/PrintStream;
23: ldc #29; //String Please enter your name>
25: invokevirtual #35; //Method
java/io/PrintStream.print:(Ljava/lang/String;)V
28: aload_1
29: invokevirtual #39; //Method
java/io/BufferedReader.readLine:()Ljava/lang/String;
32: astore_2
33: goto 37
36: return
Any idea why this might not be working?
Thanks!
Andrew Jr.
Re: Having trouble with example in the manual
Posted by Andrew Cornwall <an...@gmail.com>.
Looks as if I found my answer. The manual reads:
il.append(new ASTORE(name));
Upon normal execution we jump behind exception handler, the target address
is not known yet.
GOTO g = new GOTO(null);
InstructionHandle try_end = il.append(g);
but it should read:
GOTO g = new GOTO(null);
InstructionHandle try_end = il.append(g);
il.append(new ASTORE(name));
in order to generate the same code that the JDK does.
Andrew Jr.
On 10/3/07, Andrew Cornwall <an...@gmail.com> wrote:
>
> I'm trying to get the example in the manual running. The first thing I
> noticed was:
>
> mg.addExceptionHandler(try_start, try_end, handler, "
> java.io.IOException");
>
> which under 5.2 doesn't seem to work. I replaced that with:
>
> mg.addExceptionHandler(try_start, try_end, handler, new ObjectType("
> java.io.IOException"));
>
>
> After doing this, I get a .class file - but when I try to run the class
> under JDK 1.5, I see:
>
> Exception in thread "main" java.lang.ClassFormatError: Illegal exception
> table range in class file HelloWorld
> at java.lang.ClassLoader.defineClass1(Native Method)
> at java.lang.ClassLoader.defineClass (ClassLoader.java:620)
> at java.security.SecureClassLoader.defineClass(
> SecureClassLoader.java:124)
> at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
> at java.net.URLClassLoader.access$100 (URLClassLoader.java:56)
> at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.net.URLClassLoader.findClass(URLClassLoader.java :188)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
> at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
> at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
>
> javap lists the exception table as being from 20 to 36 target 36 - which
> looks valid to me:
>
> 20: getstatic #27; //Field
> java/lang/System.out:Ljava/io/PrintStream;
> 23: ldc #29; //String Please enter your name>
> 25: invokevirtual #35; //Method
> java/io/PrintStream.print:(Ljava/lang/String;)V
> 28: aload_1
> 29: invokevirtual #39; //Method
> java/io/BufferedReader.readLine:()Ljava/lang/String;
> 32: astore_2
> 33: goto 37
> 36: return
>
> Any idea why this might not be working?
>
> Thanks!
>
> Andrew Jr.
>