Community
Participate
Working Groups
Hi, I try to use a jar file generated with ajc (<iajc outJar="sources.jar" incremental="false" source="1.4" Xreweavable="true">) as inpath option of the next task: <iajc incremental="false" source="1.4" destdir="${build.classes}" inpath="${sources.jar}" > If "sources.jar" does not contain any aspect, the task will continue to fail if the jar was generated with ajc(with or without the Xreweavable option). It will only work if the jar file was generated with javac (javac + jar tasks). I use ant 1.6.2 and aspectj 1.2.1. When using aspectj 1.2, there are other problems, apparently because the Xreweavable option is ignored. The exception: [iajc] ABORT [iajc] [iajc] Exception thrown from AspectJ 1.2 [iajc] This might be logged as a bug already -- find current bugs at [iajc] http://bugs.eclipse.org/bugs/buglist.cgi?product=AspectJ&component=Co mpiler [iajc] Bugs for exceptions thrown have titles File:line from the top stack, [iajc] e.g., "SomeFile.java:243" [iajc] If you don't find the exception below in a bug, please add a new bug [iajc] at http://bugs.eclipse.org/bugs/enter_bug.cgi?product=AspectJ [iajc] To make the bug a priority, please include a test program [iajc] that can reproduce this exception. [iajc] unknown attributeorg.aspectj.weaver.WeaverVersion [iajc] unknown attributeorg.aspectj.weaver.WeaverVersion [iajc] org.aspectj.weaver.BCException: unknown attributeorg.aspectj.weaver.Wea verVersion [iajc] at org.aspectj.weaver.AjAttribute.read(AjAttribute.java:109) [iajc] at org.aspectj.weaver.bcel.BcelAttributes.readAjAttributes(BcelAttr ibutes.java:38) [iajc] at org.aspectj.weaver.bcel.BcelObjectType.unpackAspectAttributes(Bc elObjectType.java:166) [iajc] at org.aspectj.weaver.bcel.BcelObjectType.<init>(BcelObjectType.jav a:85) [iajc] at org.aspectj.weaver.bcel.BcelWorld.makeBcelObjectType(BcelWorld.j ava:202) [iajc] at org.aspectj.weaver.bcel.BcelWorld.addSourceObjectType(BcelWorld. java:232) [iajc] at org.aspectj.weaver.bcel.BcelWeaver.addClassFile(BcelWeaver.java: 270) [iajc] at org.aspectj.weaver.bcel.BcelWeaver.addJarFile(BcelWeaver.java:20 3) [iajc] at org.aspectj.ajdt.internal.core.builder.AjBuildManager.initBcelWo rld(AjBuildManager.java:447) [iajc] at org.aspectj.ajdt.internal.core.builder.AjBuildManager.doBuild(Aj BuildManager.java:143) [iajc] at org.aspectj.ajdt.internal.core.builder.AjBuildManager.batchBuild (AjBuildManager.java:94) [iajc] at org.aspectj.ajdt.ajc.AjdtCommand.doCommand(AjdtCommand.java:102) [iajc] at org.aspectj.ajdt.ajc.AjdtCommand.runCommand(AjdtCommand.java:53) [iajc] at org.aspectj.tools.ajc.Main.run(Main.java:280) [iajc] at org.aspectj.tools.ajc.Main.runMain(Main.java:217) [iajc] at org.aspectj.tools.ant.taskdefs.AjcTask.executeInSameVM(AjcTask.j ava:1157) [iajc] at org.aspectj.tools.ant.taskdefs.AjcTask.execute(AjcTask.java:954) [iajc] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java: 275) [iajc] at org.apache.tools.ant.Task.perform(Task.java:364) [iajc] at org.apache.tools.ant.Target.execute(Target.java:341) [iajc] at org.apache.tools.ant.Target.performTasks(Target.java:369) [iajc] at org.apache.tools.ant.Project.executeTarget(Project.java:1214) [iajc] at org.apache.tools.ant.Project.executeTargets(Project.java:1062) [iajc] at org.apache.tools.ant.Main.runBuild(Main.java:673) [iajc] at org.apache.tools.ant.Main.startAnt(Main.java:188) [iajc] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:196) [iajc] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:55)
The attribute not being understood in the error message is WeaverVersion - this attribute was added right before shipment of AspectJ 1.2.1. An AspectJ 1.2.1 or above weaver will understand them. It sounds like the iajc being executed is pre-1.2.1 - what is the classpath you used in the ANT script to define the iajc task? Was it pointing to an old install of AspectJ (<1.2.1) ? The message 'Exception thrown from AspectJ 1.2' makes it sound like it was basic AspectJ 1.2.0 which did not understand this attribute. Ironically this attribute has been added so that future weavers can know which attributes will/won't exist in a class file and cope appropriately...
That's correct! Thanks! Now it is the same problem as in 1.2: if the original jar (sources.jar) does not have any aspect, the jar can be woven, but if it already has aspects, reweaving the jar fails. It might be a problem with the Xreweavable option, as the jars generated with or without this option are the same size.
are you able to try building sources.jar from the command line suppling -Xreweavable that way? (I'm trying to ascertain if the problem is in the iajc processing of that option or not). Reweavable versions of the classes should definetly be larger. Also, is it a problem if you need to build the initial sources.jar with javac & jar - if there are no aspects in the input for sources.jar?
It is the same problem from command line, too. It works fine if sources.jar does not have any aspect. In this case (with no aspect) the jar can be built with ajc and Xreweavable option (no need to use javac + jar; "ajc -outjar" works) and supports (re)weaving (I can use it in inpath). If the jar has aspects, apparently it cannot be re-woven (cannot be in inpath).
I've done minimal tests of reweaving an aspect and found no surprises, so we might need to know more about your aspect to find out what the problem is. For those writing test cases, here's how you'd specify it for the harness (after updating): <ajc-test dir="bugs/reweavable" pr="83717 title="reweavable aspects"> <compile files="Reweavable.java" options="-Xreweavable" outjar="rw.jar"/> <compile files="rw.jar"/> <run class="Reweavable"/> </ajc-test> I only tried a basic one, but the aspect does advise itself: public class Reweavable { public static void main(String[] args) { System.out.println("in main"); } static aspect A { public A() {} after() returning: execution(void A.foo()) { System.out.println("advising aspect method foo"); } before() : execution(void main(String[])) { System.out.println("before main"); foo(); } void foo() {} } } Unless someone objects, I'll move this to the compiler component and reassign to Andy.
reassigning as compiler/weaver issue...
Here is the problem: 1. the code that works package testreweave; public interface InterfaceB { public void b(); } //----------- package testreweave; public interface InterfaceA extends InterfaceB { public void a(); } //----------- package testreweave; public class A implements InterfaceA { public void a() { System.out.println("A.a"); } public void b() { System.out.println("introduced A.b"); } } //----------- package testreweave; public privileged aspect IntroduceB { // declare parents: InterfaceA extends InterfaceB; // public void A.b() { // System.out.println("introduced A.b"); // } } //----------- With the sources above generate srcjar.jar: >ajc -outjar srcjar.jar -argfile srclist1.lst -Xreweavable //The aspect trying to reweave things import testreweave.*; public privileged aspect Reweave { public void InterfaceB.rewoven() { System.out.println("A.rewoven"); } public void A.test() { A a = new A(); a.rewoven(); } } Compile: >ajc -d binsrc -argfile srclist2.lst -inpath srcjar.jar and everything is fine. ****************** 2. The code that doesn't work: uncomment the code in the aspect IntroduceB and comment out the corresponding code in the affected classes. package testreweave; public interface InterfaceB { public void b(); } // ----------- package testreweave; public interface InterfaceA /*extends InterfaceB*/ { public void a(); } // ----------- package testreweave; public privileged aspect IntroduceB { declare parents: InterfaceA extends InterfaceB; public void A.b() { System.out.println("introduced A.b"); } } // ----------- package testreweave; public class A implements InterfaceA { public void a() { System.out.println("A.a"); } // public void b() { // System.out.println("introduced A.b"); // } } With the sources above generate srcjar.jar: ajc -outjar srcjar.jar -argfile srclist1.lst -Xreweavable //The aspect trying to reweave things import testreweave.*; public privileged aspect Reweave { public void InterfaceB.rewoven() { System.out.println("A.rewoven"); } public void A.test() { A a = new A(); a.rewoven(); } } > ajc -d binsrc -argfile srclist2.lst -inpath srcjar.jar ..\TestReweave\src\Reweave.aj:11 error The method rewoven() is undefined for the type A a.rewoven(); 1 error, 1 warning Hope I haven't missed anything and you can reproduce the error. I used aspectj1.2 for this example, but I think it's the same problem with 1.2.1
for investigation in aj5m3
not generics, postponing until after M3
This is exactly the same problem as discussed in bug 108099. When re-processing a reweavable type that was targetted by ITDs we fail to take into account any new ITDs and just apply the ones applied previously. In this case the rewoven method is never added to A because A was targetted by an ITD in a previous compilation.
Whilst looking at this bug, I found a problem when some systems containing ITDs has been compiled with 1.2.1 and is to be processed with 1.5. between 1.2.1 and 1.5.0 we have added the ability for type mungers (representing ITDs) to remember their source location when they are serialized which enables us to do a better job creating relationships in the structure model and reporting weaving info. We (I) didn't guard the loading of the source location based on whether an input .class file was marked as being built with AspectJ5. So we attempted to load source locations for type mungers when the input code was built by 1.2 or 1.2.1 - this causes the classic EOFExceptions when processing attributes. I've fixed it now ;)
NPE fix and reweavable ITD fix checked in. Effectively changed the code that processes existing weaverstateinfo objects (which occur in reweavable types) - original processing didn't allow for these types to be rewoven, but now it does. I have *NOT* put this fix back into AspectJ1.2.1, it is only in AspectJ5 - it could be backported if you desperately need it????
Fix in 1.5.0 is available now - raised 111413 to cover a possible backport.