Bug 59921 - NoSuchMethodError: InstructionFactory.createNewArray in examples/spacewar
Summary: NoSuchMethodError: InstructionFactory.createNewArray in examples/spacewar
Status: RESOLVED DUPLICATE of bug 61374
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.1.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 1.2.1   Edit
Assignee: Jim Hugunin CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-04-26 07:06 EDT by Mert Nuhoglu CLA
Modified: 2004-10-21 04:32 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mert Nuhoglu CLA 2004-04-26 07:06:59 EDT
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.
Comment 1 Andrew Clement CLA 2004-04-26 10:42:52 EDT
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?
Comment 2 Andrew Clement CLA 2004-05-24 06:57:59 EDT
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.
Comment 3 Andrew Clement CLA 2004-05-24 11:53:11 EDT
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.

Comment 4 Andrew Clement CLA 2004-07-26 03:30:19 EDT
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 ***
Comment 5 Adrian Colyer CLA 2004-10-21 04:32:12 EDT
Fix released as part of AspectJ 1.2.1