RE: [aspectwerkz-user] Weaving private methods

"Bygrave, Graham BGI UK" <[email protected]> Thu, 2 Jun 2005 15:29:26 +0100
Newsgroups gmane.comp.java.aspectwerkz.user
Message-ID <03D8E4DA4B752943B2F3F073ABDAE83630421A@ldnnte2k032.insidelive.net>
Hi Alexandre,
Indeed I am trying to weave constructors.  Intesting you don't hit this though.  I note that you recommend the JRockit compiler/vm for running aspectwerkz and weblogic together.  Maybe this is the source of my problem?

I am using aspectwerkz 2.0 final, so I guess it's not that.

Best wishes,
Graham.


-----Original Message-----
From: Alexandre Vasseur [mailto:[email protected]]
Sent: 02 June 2005 15:21
To: [email protected]
Subject: Re: [aspectwerkz-user] Weaving private methods


private member interception is supported

From what you post here, I can imagine you have an advice on a
constructor call, for a class that would instantiate an instance of
himself in the static initialiezer ie like below and I don't have the
problem you have.

Are you using 2.0 final ? Can you reproduce it ?
Alex


package test.priv.sub;
public class PrivateTarget {
    public static PrivateTarget s_singleton = new PrivateTarget(1);

    private PrivateTarget(int i) {
        int j = i;
    }

}

I could weave that with:

package test.priv;
public class PrivateCtorTest extends TestCase {

    public void testPrivateCtorCall() {
        PrivateTarget i = PrivateTarget.s_singleton;
        assertTrue(i!=null);
    }

    public static class TestAspect {

        @Before("within(test.priv.sub.PrivateTarget) && call(*.new(..))")
        public void before() {
            int i = 0;
        }
    }

    public static void main(String[] args) {
        junit.textui.TestRunner.run(suite());
    }

    public static junit.framework.Test suite() {
        return new junit.framework.TestSuite(PrivateCtorTest.class);
    }
}


On 6/2/05, Bygrave, Graham BGI UK <[email protected]> wrote:
> I'm trying to weave private methods and yet I get a an IllegalAccessError when aspectwerkz generated classes try to call them - not surprising given that the call seems to be direct (i.e. not using reflection).  Is there any way around this?
> 
> Thanks,
> Graham.
> 
> java.lang.IllegalAccessError: tried to access method weblogic.security.acl.internal.AuthenticatedSubject.<init>(Z)V from class weblogic.security.acl.internal.AuthenticatedSubject_4__86728660__1385029237__253649152___AW_JoinPoint
>         at weblogic.security.acl.internal.AuthenticatedSubject_4__86728660__1385029237__253649152___AW_JoinPoint.invoke(Unknown Source)
>         at weblogic.security.acl.internal.AuthenticatedSubject.<clinit>(AuthenticatedSubject.java:29)
>         at java.lang.Class.forName0(Native Method)
>         at java.lang.Class.forName(Class.java:141)
>         at weblogic.security.service.SecurityServiceManager_4_834538669_1818100967__253649152___AW_JoinPoint.aw$staticinitialization(Unknown Source)
>         at weblogic.security.service.SecurityServiceManager_4_834538669_1818100967__253649152___AW_JoinPoint.<clinit>(Unknown Source)
>         at weblogic.security.service.SecurityServiceManager.initializeKernelID(SecurityServiceManager.java:1071)
>         at weblogic.security.service.SecurityServiceManager.<clinit>(SecurityServiceManager.java:82)
>         at weblogic.security.service.PrivilegedActions$GetKernelIdentityAction.run(PrivilegedActions.java:45)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at weblogic.t3.srvr.T3Srvr.<clinit>(T3Srvr.java:161)
>         at weblogic.Server.main(Server.java:32)
>