Bugs item #773087, was opened at 2003-07-17 18:05
Message generated for change (Comment added) made by letiemble
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=376685&aid=773087&group_id=22866
Category: Aspects
Group: CVS HEAD
>Status: Closed
>Resolution: Out of Date
Priority: 5
Submitted By: Laurent Etiemble (letiemble)
Assigned to: Bill Burke (patriot1burke)
Summary: Multiple mixins not supported
Initial Comment:
Hi,
I went through this bug while playing with mixin.
When multiple mixins are defined for a class, the
following exception is raised on mixin call :
Exception in thread "main"
java.lang.IllegalArgumentException: object is not an
instance of declaring class
at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at
org.jboss.aop.ClassAdvisor$MethodTailInterceptor.invoke(Unknown
Source)
at org.jboss.aop.Invocation.invokeNext(Unknown
Source)
at
TracingInterceptor.invoke(TracingInterceptor.java:43)
at org.jboss.aop.Invocation.invokeNext(Unknown
Source)
at
org.jboss.aop.ClassAdvisor.invokeMethod(Unknown Source)
at POJO._added_m$3(POJO.java)
at POJO.disableLogging(POJO.java)
at POJO.POJO$main$WithoutAdvisement(POJO.java:42)
at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at
org.jboss.aop.ClassAdvisor$MethodTailInterceptor.invoke(Unknown
Source)
at org.jboss.aop.Invocation.invokeNext(Unknown
Source)
at
TracingInterceptor.invoke(TracingInterceptor.java:43)
at org.jboss.aop.Invocation.invokeNext(Unknown
Source)
at
org.jboss.aop.ClassAdvisor.invokeMethod(Unknown Source)
at
org.jboss.aop.ClassAdvisor.invokeMethod(Unknown Source)
at POJO._added_m$1(POJO.java)
at POJO.main(POJO.java)
How to reproduce :
------------------
(Inspired from the example 3 of the O'Reilly article)
- Define a POJO class
- Define a TracingMixin class that implements Tracing
- Define a LoggingMixin class that implements Logging
- Apply the two mixins on the POJO class
- Make invocations on both mixin methods.
If the TracingMixin is first applied, the exception
occured on a Logging invocation.
If the LoggingMixin is first applied, the exception
occured on a Tracing invocation.
Analysis :
----------
When a mixin is added to a class, a mixin invocation
method is created to handle the mixin specific
invocations. This is done by the
"createMixinInvokeMethod" method in the
"org.jboss.aop.Instrumentor" class. But the name of the
created method is unique (or a least the generated one
by javassist) even for multiple mixin addition.
Workaround :
------------
The solution is to have a dedicated mixin invocation
method per mixin class. In the
"createMixinInvokeMethod" method in the
"org.jboss.aop.Instrumentor" class, the signature of
the created method has to be changed.
Replace :
"public java.lang.Object mixinInvoke(java.lang.Object[]
args, long i)" + ...
With :
"public java.lang.Object mixinInvoke" +
mixinFieldName(mixinClass) + "(java.lang.Object[] args,
long i)" + ...
Laurent.
----------------------------------------------------------------------
>Comment By: Laurent Etiemble (letiemble)
Date: 2004-08-04 22:47
Message:
Logged In: YES
user_id=437455
Hi,
This bug was raised long before the refactoring of JBossAOP by Bill
Burke. I think this bug is outdated and I agree with you that it must be
closed.
Laurent.
----------------------------------------------------------------------
Comment By: Tomasz Nazar (nthx)
Date: 2004-08-04 12:48
Message:
Logged In: YES
user_id=807475
My comment is:
This bug #773087 should be closed. I tried multiple-mixins
with JBossAOP-Beta-3 and they work.
I wrote POJO & Driver class myself. Two mixins
(StringableMixin + Stringable(toString) and LoggableMixin +
Loggable(getLogger)).
I adviced class POJO with both of them by:
<annotation tag="loggable" class="jbossaop.POJO">
<class />
</annotation>
<introduction expr="class(@loggable)">
<mixin>
<interfaces>jbossaop.Loggable</interfaces>
<class>jbossaop.LoggableMixin</class>
<construction>new jbossaop.LoggableMixin()</construction>
</mixin>
</introduction>
<annotation tag="stringable" class="jbossaop.POJO">
<class />
</annotation>
<introduction expr="class(@stringable)">
<mixin>
<interfaces>jbossaop.Stringable</interfaces>
<class>jbossaop.StringableMixin</class>
<construction>new
jbossaop.StringableMixin(this)</construction>
</mixin>
</introduction>
After that, I can invoke:
public class POJO
{
....
public void checkMyMixin()
{
Logger log = ((Loggable)this).getLogger();
String myRepresentation = ((Stringable)this).toString();
log.debug("Debugging my representation: " +
myRepresentation);
}
....
}
and it works...
So this bug report is improper.
--nthx
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=376685&aid=773087&group_id=22866
-------------------------------------------------------
This SF.Net email is sponsored by OSTG. Have you noticed the changes on
Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now,
one more big change to announce. We are now OSTG- Open Source Technology
Group. Come see the changes on the new OSTG site. www.ostg.com
_______________________________________________
JBoss-Development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development