Bug 263105

Summary: Reweaving after bytecode manipulation from other libraries causes ClassFormatException
Product: [Tools] AspectJ Reporter: Simone Gianni <simoneg>
Component: CompilerAssignee: aspectj inbox <aspectj-inbox>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3 CC: aclement
Version: 1.6.2   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Simone Gianni CLA 2009-01-30 16:57:30 EST
Build ID: M20080221-1800

Steps To Reproduce:
1. Setup a project having aspects.
2. Compile it with ajc
3. Run any other kind of instrumenter or enhancer (like OpenJPA enhancer, or Cobertura) in a way that also an aspect is enhanced (Cobertura instruments everything by default, and is my situation)
4. Cause a reweaving, like loading in an LTW environment or recompiling.


More information:
These steps will cause a ClassFormatException. This is caused by the way the unwoven bytecode is reconstructed. While applying the diff, the constant pool of the original class is partially reapplied, but the other enchancer have probably modified it.

As a result, BCEL fails in parsing the constant pool. In my case the stack trace is the following.

org.aspectj.apache.bcel.classfile.ClassFormatException: File: 'org.apache.magma.website.Contextualizer': Invalid byte tag in constant pool: 16
        at org.aspectj.apache.bcel.classfile.ClassParser.readConstantPool(ClassParser.java:192)
        at org.aspectj.apache.bcel.classfile.ClassParser.parse(ClassParser.java:131)
        at org.aspectj.weaver.bcel.Utility.makeJavaClass(Utility.java:504)
        at org.aspectj.weaver.bcel.BcelWeaver.addLibraryAspect(BcelWeaver.java:186) 

As a temporary workaround, compiling with -XterminateAfterCompilation solves the problem, cause it does not trigger reweaving.

While I do understand that this bug manifests itself under rather uncommon conditions, it uncovers a weakness in the reweaving system, that could tend to more and more common as bytecode manipulation gains popularity. In thse respect, AspectJ should be able to deal with other tools having manipulated the class between weaving and reweaving, at least implementing a self check when applying the diff and giving a better error message.
Comment 1 Andrew Clement CLA 2009-01-30 17:01:52 EST
this is a well known restriction - or at least well known by me ;)  Unlikely to get looked at any time soon...
Comment 2 Andrew Clement CLA 2009-01-30 17:02:43 EST
hmmm, although saying that - if we get Equinox Aspects LTW in an OSGi environment moving, it may become more important.