Community
Participate
Working Groups
I am a newbie of AspectJ. I use examples in order to learn the language better. Some of the examples don't work when I use the new patch of BCEL. I guess the problem lies in the new version of BCEL. Because when I use the old version of BCEL it works fine. spacewar didn't work. The error it produced was: org.apache.bcel.generic.InstructionFactory.createNewArray (Lorg/apache/bcel/generic/Type;S) Lorg/apache/bcel/generic/AllocationInstruction; org.apache.bcel.generic.InstructionFactory.createNewArray (Lorg/apache/bcel/generic/Type;S) Lorg/apache/bcel/generic/AllocationInstruction; java.lang.NoSuchMethodError: org.apache.bcel.generic.InstructionFactory.createNewArray (Lorg/apache/bcel/generic/Type;S) Lorg/apache/bcel/generic/AllocationInstruction; at org.aspectj.weaver.bcel.BcelShadow.makeArgsObjectArray (BcelShadow.java:849) at org.aspectj.weaver.bcel.BcelShadow.getThisJoinPointBcelVar (BcelShadow.java:797) at org.aspectj.weaver.bcel.BcelShadow.getThisJoinPointVar (BcelShadow.java:771) at org.aspectj.weaver.bcel.BcelAdvice.specializeOn(BcelAdvice.java:95) at org.aspectj.weaver.bcel.BcelShadow.prepareForMungers (BcelShadow.java:254) at org.aspectj.weaver.Shadow.implement(Shadow.java:312) at org.aspectj.weaver.bcel.BcelClassWeaver.implement (BcelClassWeaver.java:1006) at org.aspectj.weaver.bcel.BcelClassWeaver.weave (BcelClassWeaver.java:299) at org.aspectj.weaver.bcel.BcelClassWeaver.weave (BcelClassWeaver.java:77) at org.aspectj.weaver.bcel.BcelWeaver.weave(BcelWeaver.java:417) at org.aspectj.weaver.bcel.BcelWeaver.weave(BcelWeaver.java:390) at org.aspectj.weaver.bcel.BcelWeaver.weave(BcelWeaver.java:327) at org.aspectj.ajdt.internal.core.builder.AjBuildManager.weaveAndGenerateClassFile s(AjBuildManager.java:256) at org.aspectj.ajdt.internal.core.builder.AjBuildManager.doBuild (AjBuildManager.java:156) at org.aspectj.ajdt.internal.core.builder.AjBuildManager.batchBuild (AjBuildManager.java:70) at org.aspectj.ajdt.ajc.AjdtCommand.doCommand(AjdtCommand.java:99) at org.aspectj.ajdt.ajc.AjdtCommand.runCommand(AjdtCommand.java:53) at org.aspectj.tools.ajc.Main.run(Main.java:217) at org.aspectj.tools.ant.taskdefs.Ajc10.spoon(Ajc10.java:598) at org.aspectj.tools.ant.taskdefs.Ajc10.execute(Ajc10.java:484) at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:193) at org.apache.tools.ant.Task.perform(Task.java:341) at org.apache.tools.ant.Target.execute(Target.java:309) at org.apache.tools.ant.Target.performTasks(Target.java:336) at org.apache.tools.ant.Project.executeTarget(Project.java:1339) at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:397) at org.apache.tools.ant.taskdefs.CallTarget.execute (CallTarget.java:143) at org.apache.tools.ant.Task.perform(Task.java:341) at org.apache.tools.ant.Target.execute(Target.java:309) at org.apache.tools.ant.Target.performTasks(Target.java:336) at org.apache.tools.ant.Project.executeTarget(Project.java:1339) at org.apache.tools.ant.Project.executeTargets(Project.java:1255) at org.apache.tools.ant.Main.runBuild(Main.java:609) at org.apache.tools.ant.Main.start(Main.java:196) at org.apache.tools.ant.Main.main(Main.java:235) at com.intellij.rt.ant.execution.AntMain2.main(Unknown Source) I am using java 1.4.2 and Win XP. The examples, that didn't work are: spacewar, tjp and maybe some others too... But observer, telecom work fine.
I've seen related issues about the BCEL version on the lists/etc. Can I ask - it looks like you are building the project with ANT, are you using the ANT settings that we suggest? From the stack trace it looks like you are using class Ajc10 (ant task 'ajc') which is the older variant of the ANT task for AspectJ. It would be better to use the 'iajc' ANT task (which is implemented by the class AjcTask) Then when you do that, there are some subtleties to avoid picking up the wrong versions of some classes. Typically you need to fork the call to iajc: <iajc fork="true" forkclasspath="${aspectjtools.jar}" destDir="${dir.compile.source}" classpath="${jar.aspectjrt}"> ... Incidentally, you mention the old and new versions of BCEL, where are these coming from?
I've seen several people hit this and I want to track my findings. With AspectJ1.2 we have moved to a new version of BCEL - an easy way to identify the new version is through the signature for the method described in this bug as causing us problems. In AspectJ1.2 the signature is: public org.apache.bcel.generic.Instruction createNewArray (org.apache.bcel.generic.Type,short); In AspectJ1.1 the signature was: public org.apache.bcel.generic.AllocationInstruction createNewArray (org.apache.bcel.generic.Type, short); There was an error in the packaging of recent versions of AJDT that caused the old BCEL to be included in the distribution. This could (on some systems) manifest itself as NoSuchMethodError at runtime when doing a weave *if* you are weaving a method join point that has > 2 parameters *and* you use thisJoinPoint in your advice.
I see what the problem is. Certain levels of certain JVMs include BCEL classes in some of the core JVM jar files. For example I have an old version of an IBM jvm that includes bcel classes. You can check if this is the problem you are seeing by going to the command line, unsetting your classpath and running: javap org.apache.bcel.generic.InstructionFactory If that runs, you have a JVM that includes BCEL. If the version of BCEL is 'old' then the return type of the createNewArray method in the javap output will be AllocationInstruction. If this is happening to you, upgrade your JVM to a more recent version and it should be fixed - i.e. the javap command above should *fail*! Whilst you have a JVM with that old version of BCEL in, aspectj will never be able to load its more recent versions of the bcel classes.
Enhancement request 61374 is tracking the proper fix for this bug (version or rename the BCEL libraries in AJ). *** This bug has been marked as a duplicate of 61374 ***
Fix released as part of AspectJ 1.2.1