Sample code in JAVA which cannot be properly disassembled (I included bytecode as well for easy analysis)
Java
public class Class1
{
public static void Test() {
int i = 0 ;
try
{
i = 1;
}
finally
{
i = 2 ;
}
i = 3 ;
}
}
Compiled from “Class1.java”
public class Class1 extends java.lang.Object{
public Class1();
Code:
0: aload_0
1: invokespecial #1; //Method java/lang/Object."<init>":()V
4: return
public static void Test();
Code:
0: iconst_0
1: istore_0
2: iconst_1
3: istore_0
4: iconst_2
5: istore_0
6: goto 14
9: astore_1
10: iconst_2
11: istore_0
12: aload_1
13: athrow
14: iconst_3
15: istore_0
16: return
Exception table:
from to target type
2 4 9 any
9 10 9 any
}
Analogic code in Oxygene is problematic and significantly more complicated the Java
Oxygene
procedure Class1.Test;
var
i : Integer ;
begin
try
i := 1;
finally
i := 2;
end;
i := 3;
end;
Compiled from “c:\tmp\Class1.pas”
public class classlibrary1.Class1 extends java.lang.Object{
public void Test();
Code:
0: aconst_null
1: astore_1
2: aconst_null
3: astore_2
4: new #2; //class classlibrary1/Class1
7: dup
8: invokespecial #11; //Method "<init>":()V
11: astore_1
12: goto 16
15: astore_2
16: aload_2
17: ifnull 22
20: aload_2
21: athrow
22: return
Exception table:
from to target type
4 12 15 any
public classlibrary1.Class1();
Code:
0: aload_0
1: invokespecial #18; //Method java/lang/Object."<init>":()V
4: return
}
However similar try…catch code seems to works fine and Oxygene generated code is just identical
Java
public class Class1
{
public void Test() {
int i = 0 ;
try
{
i = 1;
}
catch( Exception ex)
{
i = 2 ;
}
i = 3 ;
}
}
Compiled from “Class1.java”
public class Class1 extends java.lang.Object{
public Class1();
Code:
0: aload_0
1: invokespecial #1; //Method java/lang/Object."<init>":()V
4: return
public void Test();
Code:
0: iconst_0
1: istore_1
2: iconst_1
3: istore_1
4: goto 10
7: astore_2
8: iconst_2
9: istore_1
10: iconst_3
11: istore_1
12: return
Exception table:
from to target type
2 4 7 Class java/lang/Exception
}
Oxygene
procedure Class1.Test;
var
i : Integer ;
begin
try
i := 1;
except
i := 2;
end;
i := 3;
end;
Compiled from “c:\tmp\Class1.pas”
public class classlibrary1.Class1 extends java.lang.Object{
public void Test();
Code:
0: iconst_0
1: istore_1
2: aconst_null
3: astore_2
4: iconst_1
5: istore_1
6: goto 10
9: astore_2
10: iconst_2
11: istore_1
12: aload_2
13: ifnull 18
16: aload_2
17: athrow
18: iconst_3
19: istore_1
20: return
Exception table:
from to target type
4 6 9 any
public classlibrary1.Class1();
Code:
0: aload_0
1: invokespecial #18; //Method java/lang/Object."<init>":()V
4: return
}
I tested it using JD.
I will try to send you on email my project and generated jar. Most classes that show disassembly errors are not reflected in Eclipse and errors are reported for methods where try finally was used. Strangely in this simple test the reflection works fine and I can use this class instance.