Hi, Thanks for replying. The mg variable indead point to a constructor(<init>). How can I fix my problem?
Kind regards, -----Oorspronkelijk bericht----- Van: Dick Eimers [mailto:[EMAIL PROTECTED] Verzonden: donderdag 15 juli 2004 15:10 Aan: BCEL Users List Onderwerp: Re: JavaClassFileOutputException: Stack underflow Instrumenting object initialization methods, methods with the special name <init> (constructors are a Java programming language concept) require caution. Various discussions covered the topic, but it comes down to that all object initializers should invoke another object initializer either in the current class or the superclass (chaining). If your code does not rely on a reference to the object that is being initialized (the Java programming language *this*) then it is safe to insert the code at the beginning of the instructionlist.. > I'm trying to insert some code in the constructor of certain classes. The code should be getting the current singleton instance of a class 'MySingleton' and call a method 'myMethod' on this instance. My code is as follows : > > InstructionList il = mg.getInstructionList(); > il.insert(factory.createInvoke("MySingleTon", "getInstance", new ObjectType("MySingleton"), Type.NO_ARGS, Constants.INVOKESTATIC)); > il.insert(InstructionFactory.createLoad(Type.OBJECT, 0)); > il.insert(factory.createInvoke("java.lang.Object", "getClass", new ObjectType("java.lang.Class"), Type.NO_ARGS, Constants.INVOKEVIRTUAL)); > il.insert(factory.createInvoke("java.lang.Class", "getName", Type.STRING, Type.NO_ARGS, Constants.INVOKEVIRTUAL)); > il.insert(InstructionConstants.ACONST_NULL); > il.insert(factory.createInvoke("MySingleton", "myMethod", Type.VOID, new Type[] { Type.STRING, new ObjectType("MyObject") }, Constants.INVOKEVIRTUAL)); > > mg.setInstructionList(il); > mg.setMaxStack(); If mg is a <init> then you're about to have a conflict with the verifier.. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.713 / Virus Database: 469 - Release Date: 30/06/2004 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.713 / Virus Database: 469 - Release Date: 30/06/2004 --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
