My statement was true: by default ASM will give errors when processing
bytecode with custom attributes. I didn't mean to imply that there's some
fundamental problem (I think that's how you interpreted it). Of course ASM
can handle them, but until now the default policy has been to not accept
unknown attributes, and to put the onus on the caller to specifically enable
them. I previously submitted a patch to jarjar so it can use ASM to preserve
AspectJ attributes (this is a case where preserving attributes is clearly
critical).
On the good news front, Eugene Kuleshov is proposing a means to facilitate
using custom attributes and having the AspectJ attributes supported by
default.
When this came up before on the ASM mailing list, one ASM developer asked
"why aren't you using annotations"? In general, using annotations would
pick up better tools support. If a change like that were contemplated,
clearly 5.0 would be the release for it, although I don't think it would be
worth a delay, an increase in instability, or breaking backward
compatibility to achieve.
-----Original Message-----
From: aspectj-dev-bounces@xxxxxxxxxxx
[mailto:aspectj-dev-bounces@xxxxxxxxxxx] On Behalf Of Alexandre Vasseur
Sent: Thursday, October 20, 2005 7:58 AM
To: AspectJ developer discussions
Subject: Re: [aspectj-dev] AspectJ Custom Attributes
Those are untrue statement about ASM. ASM can handle them. There is
just a need of explicit knowledge about those. This is indeed the most
important limitation in using ASM and AspectJ together.
I personally think AspectJ should move to real class level annotations
instead of custom attributes. There is no need to change a lot of
things I think. Some generic class level annotation with a single
byte[] attribute is just equivalent to custom attributes - but a bit
cleaner and does not requires any special treatment. The deal is about
handling backward compatibility where needed.
Given that ASM is widespread (jarjar, many bytecode based products
commercial or not doing performance monitoring or other things etc) I
would hope a more pragmatic approach and thinking from all the AspectJ
dev team about that and ditching the old custom attributes within the
1.5 release time frame. This would solve the issue once and for all at
the right time.
That said I invite ASM folks to give it some more thinking and see if
they cannot come up quickly with a defaulted behavior that would keep
custom attributes without any special handling. That said AspectJ is
at the corner for 1.5 final, while a new version of ASM that would
handle this is not (and I remember Eric already told me this was
actually not possible given the visitor based design of ASM).
Below a code snip to preserve AjAattribute with ASM ( I cross posted
on ASM list) for anyone who needs to do that:
The AJ attributes are sort of serialized bytes. I think some agnostic
wrapper can make the trick for ASM to not lose those and pass them
thru as you say.
Something like
class SerializedAttribute extends asm.Attribute
public SerializedAttribute(final String type, final byte[] bytes) {
super(type);
m_bytes = bytes;
}
// prepare one prototype for each org.aspectj.weaver.AjAttribute inner
class:
new SerializedAttribute(AjAttribute.Aspect.AttributeName, null),
new SerializedAttribute(AjAttribute.AdviceAttribute.AttributeName,
null),
//etc.
pass an array of prototype when doing the ASM ClassReader.accept(...)
implement an ASM class adapter with a visitAttribute method
This one will gets called for each of the custom AJ attribute
From there you can do like:
public void visitAttribute(Attribute attribute) {
if (attribute.type.startsWith(AjAttribute.AttributePrefix)) {
if (attribute instanceof SerializedAttribute) {
final byte[] bytes = ((SerializedAttribute)
attribute).getBytes();
AjAttribute attr = AjAttribute.read(s_version,
attribute.type, bytes, null, s_handler);
to read the attribute with ASM if you need to.
If you don't, just pass it thru (hence don't implement this
visitAttribute method if using an adapter etc).
Alex