Bug in BCEL or BCELifier

theUser BL <[email protected]> Sun, 15 Nov 2009 13:29:20 +0000
Newsgroups gmane.comp.jakarta.bcel.user
Message-ID <[email protected]>
--_416ce3e5-76f2-4c3b-88fb-d63ff3ab878b_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


Hi!

Have a look at this one:
------------------------
C:\>dir
 Volume in Laufwerk C: hat keine Bezeichnung.
 Volumeseriennummer: 5481-B7B1

 Verzeichnis von C:\

15.11.2009  00:02    <DIR>          .
15.11.2009  00:02    <DIR>          ..
15.11.2009  00:04               372 Test.java
               1 Datei(en)=2C            372 Bytes
               2 Verzeichnis(se)=2C 158.248.124.416 Bytes frei

C:\>type Test.java
public class Test {

  public static void TestMethod (int first=2C double second=2C float third)=
 {

  third =3D 15=3B
  first =3D 12=3B
  second =3D 17.2=3B
  third =3D 19=3B
  System.out.println(first)=3B
  System.out.println(second)=3B
  System.out.println(third)=3B
  System.out.println(third)=3B

  }

  public static void main(String[] args) {
    TestMethod (0=2C0=2C0)=3B
  }

}

C:\>javac Test.java

C:\>java Test
12
17.2
19.0
19.0

C:\>java org.apache.bcel.util.BCELifier Test > TestCreator.java

C:\>type TestCreator.java
import org.apache.bcel.generic.*=3B
import org.apache.bcel.classfile.*=3B
import org.apache.bcel.*=3B
import java.io.*=3B

public class TestCreator implements Constants {
  private InstructionFactory _factory=3B
  private ConstantPoolGen    _cp=3B
  private ClassGen           _cg=3B

  public TestCreator() {
    _cg =3D new ClassGen("Test"=2C "java.lang.Object"=2C "Test.java"=2C ACC=
_PUBLIC | ACC_SUPER=2C new String[] {  })=3B

    _cp =3D _cg.getConstantPool()=3B
    _factory =3D new InstructionFactory(_cg=2C _cp)=3B
  }

  public void create(OutputStream out) throws IOException {
    createMethod_0()=3B
    createMethod_1()=3B
    createMethod_2()=3B
    _cg.getJavaClass().dump(out)=3B
  }

  private void createMethod_0() {
    InstructionList il =3D new InstructionList()=3B
    MethodGen method =3D new MethodGen(ACC_PUBLIC=2C Type.VOID=2C Type.NO_A=
RGS=2C new String[] {  }=2C "<init>"=2C "Test"=2C il=2C _cp)=3B

    InstructionHandle ih_0 =3D il.append(_factory.createLoad(Type.OBJECT=2C=
 0))=3B
    il.append(_factory.createInvoke("java.lang.Object"=2C "<init>"=2C Type.=
VOID=2C Type.NO_ARGS=2C Constants.INVOKESPECIAL))=3B
    InstructionHandle ih_4 =3D il.append(_factory.createReturn(Type.VOID))=
=3B
    method.setMaxStack()=3B
    method.setMaxLocals()=3B
    _cg.addMethod(method.getMethod())=3B
    il.dispose()=3B
  }

  private void createMethod_1() {
    InstructionList il =3D new InstructionList()=3B
    MethodGen method =3D new MethodGen(ACC_PUBLIC | ACC_STATIC=2C Type.VOID=
=2C new Type[] { Type.INT=2C Type.DOUBLE=2C Type.FLOAT }=2C new String[] { =
"arg0"=2C "arg1"=2C "arg2" }=2C "TestMethod"=2C "Test"=2C il=2C _cp)=3B

    InstructionHandle ih_0 =3D il.append(new PUSH(_cp=2C 15.0))=3B
    il.append(_factory.createStore(Type.FLOAT=2C 3))=3B
    InstructionHandle ih_3 =3D il.append(new PUSH(_cp=2C 12))=3B
    il.append(_factory.createStore(Type.INT=2C 0))=3B
    InstructionHandle ih_6 =3D il.append(new PUSH(_cp=2C 17.2))=3B
    il.append(_factory.createStore(Type.DOUBLE=2C 1))=3B
    InstructionHandle ih_10 =3D il.append(new PUSH(_cp=2C 19.0))=3B
    il.append(_factory.createStore(Type.FLOAT=2C 3))=3B
    InstructionHandle ih_13 =3D il.append(_factory.createFieldAccess("java.=
lang.System"=2C "out"=2C new ObjectType("java.io.PrintStream")=2C Constants=
.GETSTATIC))=3B
    il.append(_factory.createLoad(Type.INT=2C 0))=3B
    il.append(_factory.createInvoke("java.io.PrintStream"=2C "println"=2C T=
ype.VOID=2C new Type[] { Type.INT }=2C Constants.INVOKEVIRTUAL))=3B
    InstructionHandle ih_20 =3D il.append(_factory.createFieldAccess("java.=
lang.System"=2C "out"=2C new ObjectType("java.io.PrintStream")=2C Constants=
.GETSTATIC))=3B
    il.append(_factory.createLoad(Type.DOUBLE=2C 1))=3B
    il.append(_factory.createInvoke("java.io.PrintStream"=2C "println"=2C T=
ype.VOID=2C new Type[] { Type.DOUBLE }=2C Constants.INVOKEVIRTUAL))=3B
    InstructionHandle ih_27 =3D il.append(_factory.createFieldAccess("java.=
lang.System"=2C "out"=2C new ObjectType("java.io.PrintStream")=2C Constants=
.GETSTATIC))=3B
    il.append(_factory.createLoad(Type.FLOAT=2C 3))=3B
    il.append(_factory.createInvoke("java.io.PrintStream"=2C "println"=2C T=
ype.VOID=2C new Type[] { Type.FLOAT }=2C Constants.INVOKEVIRTUAL))=3B
    InstructionHandle ih_34 =3D il.append(_factory.createFieldAccess("java.=
lang.System"=2C "out"=2C new ObjectType("java.io.PrintStream")=2C Constants=
.GETSTATIC))=3B
    il.append(_factory.createLoad(Type.FLOAT=2C 3))=3B
    il.append(_factory.createInvoke("java.io.PrintStream"=2C "println"=2C T=
ype.VOID=2C new Type[] { Type.FLOAT }=2C Constants.INVOKEVIRTUAL))=3B
    InstructionHandle ih_41 =3D il.append(_factory.createReturn(Type.VOID))=
=3B
    method.setMaxStack()=3B
    method.setMaxLocals()=3B
    _cg.addMethod(method.getMethod())=3B
    il.dispose()=3B
  }

  private void createMethod_2() {
    InstructionList il =3D new InstructionList()=3B
    MethodGen method =3D new MethodGen(ACC_PUBLIC | ACC_STATIC=2C Type.VOID=
=2C new Type[] { new ArrayType(Type.STRING=2C 1) }=2C new String[] { "arg0"=
 }=2C "main"=2C "Test"=2C il=2C _cp)=3B

    InstructionHandle ih_0 =3D il.append(new PUSH(_cp=2C 0))=3B
    il.append(new PUSH(_cp=2C 0.0))=3B
    il.append(new PUSH(_cp=2C 0.0))=3B
    il.append(_factory.createInvoke("Test"=2C "TestMethod"=2C Type.VOID=2C =
new Type[] { Type.INT=2C Type.DOUBLE=2C Type.FLOAT }=2C Constants.INVOKESTA=
TIC))=3B
    InstructionHandle ih_6 =3D il.append(_factory.createReturn(Type.VOID))=
=3B
    method.setMaxStack()=3B
    method.setMaxLocals()=3B
    _cg.addMethod(method.getMethod())=3B
    il.dispose()=3B
  }

  public static void main(String[] args) throws Exception {
    TestCreator creator =3D new TestCreator()=3B
    creator.create(new FileOutputStream("Test.class"))=3B
  }
}

C:\>ren Test.class Test.class.old

C:\>javac TestCreator.java

C:\>java TestCreator

C:\>java Test
Exception in thread "main" java.lang.VerifyError: (class: Test=2C method: m=
ain signature: ([Ljava/lang/String=3B)V) Expecting to find float on stack
Could not find the main class: Test.  Program will exit.

C:\>java -version
java version "1.6.0_16"
Java(TM) SE Runtime Environment (build 1.6.0_16-b01)
Java HotSpot(TM) Client VM (build 14.2-b01=2C mixed mode=2C sharing)

C:\>
-----------------------------------------------

With all other programs=2C which I have tested=2C it runs ok. But Test.java=
 can not be BCELified and then again with it correct created.

Btw: BCEL-Version: 5.2 (the latest one).

Greatings
theuserbl

 		 	   		 =20
_________________________________________________________________
http://redirect.gimas.net/?n=3DM0911xDateiensenden3
Gro=DFe Daten =FCbertragen? Ganz einfach mit dem Messenger!=

--_416ce3e5-76f2-4c3b-88fb-d63ff3ab878b_--