Bug 263105 - Reweaving after bytecode manipulation from other libraries causes ClassFormatException
Summary: Reweaving after bytecode manipulation from other libraries causes ClassFormat...
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.6.2   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-01-30 16:57 EST by Simone Gianni CLA
Modified: 2009-01-30 17:02 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.