declare parents on interface sometimes failing

View: New views
4 Messages — Rating Filter:   Alert me  

declare parents on interface sometimes failing

by Jim Sellers :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all.

I'm having an issue where sometimes the "declare parents" code does not properly change the parent of the class.

Declare parents is set up on HttpSession.  When using spring's MockHttpSession (which implements HttpSession), it seems that the parent class doesn't get changed correctly, so it ends up with a AbstractMethodError.
java.lang.AbstractMethodError: org.springframework.mock.web.MockHttpSession.getHashOnSet()Ljava/util/Map;

*However*, if HttpSession is in the non-test class that is being called by the test, the declare parents command seems to run correctly.

Has any one come across this?  I'm going a bit nuts because I can't seem to figure out a consistent way to be able to get this working.

Any help would be greatly appreciated.

My original writeup of what I did:
http://www.beernut.ca/jim/archives/005157.html

Thanks for your time,
Jim

_______________________________________________
aspectj-users mailing list
aspectj-users@...
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Re: declare parents on interface sometimes failing

by Andy Clement :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Jim,

Whether the aspect can do the weaving (in this case change the
parents) can depend upon which classloader loads the type targetted
for weaving.  If you add '-debug' to the aop.xml weaver options
section it will produce messages for which types the weaver is being
passed for weaving (more details here:
http://andrewclement.blogspot.com/2009/02/load-time-weaving-basics.html
).  If your HttpSession doesn't get passed to the weaver, you won't
see a log entry and it must be getting loaded 'somewhere else' higher
up.

Are you able to target the MockHttpSession class instead? (if that is
always being loaded by the correct loader)

Did you try the Spring AOP forums:
http://forum.springsource.org/forumdisplay.php?f=31 - lots of experts
on there, in this kind of area.

cheers,
Andy

2009/11/10 Jim Sellers <jim.sellers@...>:

> Hi all.
>
> I'm having an issue where sometimes the "declare parents" code does not
> properly change the parent of the class.
>
> Declare parents is set up on HttpSession.  When using spring's
> MockHttpSession (which implements HttpSession), it seems that the parent
> class doesn't get changed correctly, so it ends up with a
> AbstractMethodError.
> java.lang.AbstractMethodError:
> org.springframework.mock.web.MockHttpSession.getHashOnSet()Ljava/util/Map;
>
> *However*, if HttpSession is in the non-test class that is being called by
> the test, the declare parents command seems to run correctly.
>
> Has any one come across this?  I'm going a bit nuts because I can't seem to
> figure out a consistent way to be able to get this working.
>
> Any help would be greatly appreciated.
>
> My original writeup of what I did:
> http://www.beernut.ca/jim/archives/005157.html
>
> Thanks for your time,
> Jim
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@...
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>
_______________________________________________
aspectj-users mailing list
aspectj-users@...
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Re: declare parents on interface sometimes failing

by Jim Sellers :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Andy.

Thanks for the helpful links.

I made a minimal test app and ran it twice - one with it set to fail and one to pass (just commenting out a link that links to code that uses HttpSession).

Here's a snipit from the failure pass:
[IsolatedClassLoader@1b0889a] info register aspect com.example.auditor.aspects.ClusterableHttpSessionAspect
[AppClassLoader@92e78c] weaveinfo Join point 'method-call(void org.springframework.mock.web.MockHttpSession.setAttribute(java.lang.String, java.lang.Object))' in Type 'com.example.TempTest' (TempTest.java:34) advised by before advice from 'com.example.auditor.aspects.ClusterableHttpSessionAspect' (ClusterableHttpSessionAspect.aj:57) [with runtime test]
[AppClassLoader@92e78c] weaveinfo Join point 'method-execution(void com.example.TempTest.test())' in Type 'com.example.TempTest' (TempTest.java:32) advised by afterReturning advice from 'com.example.auditor.aspects.ClusterableHttpSessionAspect' (ClusterableHttpSessionAspect.aj:102)
[AppClassLoader@92e78c] weaveinfo Join point 'method-execution(void com.example.TempTest.test())' in Type 'com.example.TempTest' (TempTest.java:32) advised by afterThrowing advice from 'com.example.auditor.aspects.ClusterableHttpSessionAspect' (ClusterableHttpSessionAspect.aj:142)

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.example.TempTest
[AppClassLoader@92e78c] weaveinfo Join point 'method-call(void javax.servlet.http.HttpSession.setAttribute(java.lang.String, java.lang.Object))' in Type 'com.example.Temp' (Temp.java:8) advised by before advice from 'com.example.auditor.aspects.ClusterableHttpSessionAspect' (ClusterableHttpSessionAspect.aj:57) [with runtime test]
[AppClassLoader@92e78c] weaveinfo Join point 'method-call(void org.springframework.mock.web.MockHttpSession.setAttribute(java.lang.String, java.lang.Object))' in Type 'org.springframework.mock.web.MockHttpSession' (MockHttpSession.java:161) advised by before advice from 'com.example.auditor.aspects.ClusterableHttpSessionAspect' (ClusterableHttpSessionAspect.aj:57) [with runtime test]
[AppClassLoader@92e78c] weaveinfo Extending interface set for type 'javax.servlet.http.HttpSession' (HttpSession.java) to include 'com.example.auditor.aspects.ClusterableHttpSessionAspect$ClusterableHttpSession' (ClusterableHttpSessionAspect.aj)
[AppClassLoader@92e78c] info processing reweavable type com.example.auditor.aspects.ClusterableHttpSessionAspect$ClusterableHttpSession: ca\gc\ic\auditor\aspects\ClusterableHttpSessionAspect.aj
[AppClassLoader@92e78c] info successfully verified type com.example.auditor.aspects.ClusterableHttpSessionAspect exists.  Originates from ca\gc\ic\auditor\aspects\C:\AMISDevTools\workspace\IC_Project_Auditor\src\main\aspect\ca\gc\ic\auditor\aspects\ClusterableHttpSessionAspect.aj
[AppClassLoader@92e78c] weaveinfo Type 'com.example.auditor.aspects.ClusterableHttpSessionAspect$ClusterableHttpSession' (ClusterableHttpSessionAspect.aj) has intertyped field from 'com.example.auditor.aspects.ClusterableHttpSessionAspect' (ClusterableHttpSessionAspect.aj:'java.util.Map<java.lang.String,java.lang.Integer> com.example.auditor.aspects.ClusterableHttpSessionAspect$ClusterableHttpSession.hashOnSet')
[AppClassLoader@92e78c] weaveinfo Type 'com.example.auditor.aspects.ClusterableHttpSessionAspect$ClusterableHttpSession' (ClusterableHttpSessionAspect.aj) has intertyped method from 'com.example.auditor.aspects.ClusterableHttpSessionAspect' (ClusterableHttpSessionAspect.aj:'java.util.Map<java.lang.String,java.lang.Integer> com.example.auditor.aspects.ClusterableHttpSessionAspect$ClusterableHttpSession.getHashOnSet()')
[AppClassLoader@92e78c] info processing reweavable type com.example.auditor.aspects.ClusterableHttpSessionAspect: com\example\auditor\aspects\ClusterableHttpSessionAspect.aj
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.156 sec <<< FAILURE!
test(com.example.TempTest)  Time elapsed: 1.844 sec  <<< ERROR!
java.lang.AbstractMethodError: org.springframework.mock.web.MockHttpSession.getHashOnSet()Ljava/util/Map;
    at com.example.auditor.aspects.ClusterableHttpSessionAspect.ajc$interMethodDispatch1$ca_gc_ic_auditor_aspects_ClusterableHttpSessionAspect$ca_gc_ic_auditor_aspects_ClusterableHttpSessionAspect$ClusterableHttpSession$getHashOnSet(ClusterableHttpSessionAspect.aj)

And here's a snipit from the "success" pass:
[AppClassLoader@92e78c] weaveinfo Join point 'method-call(void org.springframework.mock.web.MockHttpSession.setAttribute(java.lang.String, java.lang.Object))' in Type 'com.example.TempTest' (TempTest.java:34) advised by before advice from 'com.example.auditor.aspects.ClusterableHttpSessionAspect' (ClusterableHttpSessionAspect.aj:57) [with runtime test]
[AppClassLoader@92e78c] weaveinfo Join point 'method-execution(void com.example.TempTest.test())' in Type 'com.example.TempTest' (TempTest.java:32) advised by afterReturning advice from 'com.example.auditor.aspects.ClusterableHttpSessionAspect' (ClusterableHttpSessionAspect.aj:102)
[AppClassLoader@92e78c] weaveinfo Join point 'method-execution(void com.example.TempTest.test())' in Type 'com.example.TempTest' (TempTest.java:32) advised by afterThrowing advice from 'com.example.auditor.aspects.ClusterableHttpSessionAspect' (ClusterableHttpSessionAspect.aj:142)
[AppClassLoader@92e78c] weaveinfo Extending interface set for type 'javax.servlet.http.HttpSession' (HttpSession.java) to include 'com.example.auditor.aspects.ClusterableHttpSessionAspect$ClusterableHttpSession' (ClusterableHttpSessionAspect.aj)
[AppClassLoader@92e78c] info processing reweavable type com.example.auditor.aspects.ClusterableHttpSessionAspect$ClusterableHttpSession: ca\gc\ic\auditor\aspects\ClusterableHttpSessionAspect.aj
[AppClassLoader@92e78c] info successfully verified type com.example.auditor.aspects.ClusterableHttpSessionAspect exists.  Originates from ca\gc\ic\auditor\aspects\C:\AMISDevTools\workspace\IC_Project_Auditor\src\main\aspect\ca\gc\ic\auditor\aspects\ClusterableHttpSessionAspect.aj
[AppClassLoader@92e78c] weaveinfo Type 'com.example.auditor.aspects.ClusterableHttpSessionAspect$ClusterableHttpSession' (ClusterableHttpSessionAspect.aj) has intertyped field from 'com.example.auditor.aspects.ClusterableHttpSessionAspect' (ClusterableHttpSessionAspect.aj:'java.util.Map<java.lang.String,java.lang.Integer> com.example.auditor.aspects.ClusterableHttpSessionAspect$ClusterableHttpSession.hashOnSet')
[AppClassLoader@92e78c] weaveinfo Type 'com.example.auditor.aspects.ClusterableHttpSessionAspect$ClusterableHttpSession' (ClusterableHttpSessionAspect.aj) has intertyped method from 'com.example.auditor.aspects.ClusterableHttpSessionAspect' (ClusterableHttpSessionAspect.aj:'java.util.Map<java.lang.String,java.lang.Integer> com.example.auditor.aspects.ClusterableHttpSessionAspect$ClusterableHttpSession.getHashOnSet()')

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.example.TempTest
[AppClassLoader@92e78c] weaveinfo Join point 'method-call(void javax.servlet.http.HttpSession.setAttribute(java.lang.String, java.lang.Object))' in Type 'com.example.Temp' (Temp.java:8) advised by before advice from 'com.example.auditor.aspects.ClusterableHttpSessionAspect' (ClusterableHttpSessionAspect.aj:57)
[AppClassLoader@92e78c] weaveinfo Type 'org.springframework.mock.web.MockHttpSession' (MockHttpSession.java) has intertyped field from 'com.example.auditor.aspects.ClusterableHttpSessionAspect' (ClusterableHttpSessionAspect.aj:'java.util.Map<java.lang.String,java.lang.Integer> com.example.auditor.aspects.ClusterableHttpSessionAspect$ClusterableHttpSession.hashOnSet')
[AppClassLoader@92e78c] weaveinfo Type 'org.springframework.mock.web.MockHttpSession' (MockHttpSession.java) has intertyped method from 'com.example.auditor.aspects.ClusterableHttpSessionAspect' (ClusterableHttpSessionAspect.aj:'java.util.Map<java.lang.String,java.lang.Integer> com.example.auditor.aspects.ClusterableHttpSessionAspect$ClusterableHttpSession.getHashOnSet()')
[AppClassLoader@92e78c] weaveinfo Join point 'method-call(void org.springframework.mock.web.MockHttpSession.setAttribute(java.lang.String, java.lang.Object))' in Type 'org.springframework.mock.web.MockHttpSession' (MockHttpSession.java:161) advised by before advice from 'com.example.auditor.aspects.ClusterableHttpSessionAspect' (ClusterableHttpSessionAspect.aj:57)
[AppClassLoader@92e78c] info processing reweavable type com.example.auditor.aspects.ClusterableHttpSessionAspect: com\example\auditor\aspects\ClusterableHttpSessionAspect.aj
org.springframework.mock.web.MockHttpSession@332b9a
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.359 sec

For the success one, it looks like the code is only being weaved after the tests have started.

I did not ask in the spring forums because this code isn't spring specific.  It's to test to make sure that apps will work well in a cluster wrt session use.  Some of the apps that are using it are spring, some are struts, some are a mix.

Jim


On Tue, Nov 10, 2009 at 8:27 PM, Andy Clement <andrew.clement@...> wrote:
Hi Jim,

Whether the aspect can do the weaving (in this case change the
parents) can depend upon which classloader loads the type targetted
for weaving.  If you add '-debug' to the aop.xml weaver options
section it will produce messages for which types the weaver is being
passed for weaving (more details here:
http://andrewclement.blogspot.com/2009/02/load-time-weaving-basics.html
).  If your HttpSession doesn't get passed to the weaver, you won't
see a log entry and it must be getting loaded 'somewhere else' higher
up.

Are you able to target the MockHttpSession class instead? (if that is
always being loaded by the correct loader)

Did you try the Spring AOP forums:
http://forum.springsource.org/forumdisplay.php?f=31 - lots of experts
on there, in this kind of area.

cheers,
Andy

2009/11/10 Jim Sellers <jim.sellers@...>:
> Hi all.
>
> I'm having an issue where sometimes the "declare parents" code does not
> properly change the parent of the class.
>
> Declare parents is set up on HttpSession.  When using spring's
> MockHttpSession (which implements HttpSession), it seems that the parent
> class doesn't get changed correctly, so it ends up with a
> AbstractMethodError.
> java.lang.AbstractMethodError:
> org.springframework.mock.web.MockHttpSession.getHashOnSet()Ljava/util/Map;
>
> *However*, if HttpSession is in the non-test class that is being called by
> the test, the declare parents command seems to run correctly.
>
> Has any one come across this?  I'm going a bit nuts because I can't seem to
> figure out a consistent way to be able to get this working.
>
> Any help would be greatly appreciated.
>
> My original writeup of what I did:
> http://www.beernut.ca/jim/archives/005157.html
>
> Thanks for your time,
> Jim
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@...
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>
_______________________________________________
aspectj-users mailing list
aspectj-users@...
https://dev.eclipse.org/mailman/listinfo/aspectj-users


_______________________________________________
aspectj-users mailing list
aspectj-users@...
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Re: declare parents on interface sometimes failing

by Andy Clement :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Jim,

> I made a minimal test app and ran it twice - one with it set to fail and one
> to pass (just commenting out a link that links to code that uses
> HttpSession).

so to make it pass you uncomment a reference to code that uses
HttpSession?  Thus causing HttpSession to be actively referred to?

I might be interested in the 'debug' messages that indicate when types
are being passed to the weaver, rather than just the weaveinfo
messages.

It is possibly due to the use of call pointcuts and intertype
declarations with load time weaving.  There are known issues here
because types don't always get loaded in the order we'd like and yet
we have no control because in LTW AspectJ is not in charge, it is at
the mercy of the classloader that is using it.  Altering the loading
order (by doing what you have mentioned - making references to types
more explicit) can address this problem sometimes.  However, your
scenario is a little bit complex, so I can't tell for certain that you
are suffering from this problem.

> For the success one, it looks like the code is only being weaved after the
> tests have started.

Don't you mean that in the success case HttpSession is woven before
the tests start?  In the failure case it seems to be doing the weave
too late (after the tests have started).

I see a differing ordering in the weaveinfo messages relating to
method-execution and method-call.  I think again it may help to have
the 'debug' messages as they will show the load ordering for the types
- seeing that difference may give us a bit more to go on.

I think it is worth raising a bug for this so we can sort it out:
https://bugs.eclipse.org/bugs/enter_bug.cgi?product=AspectJ

Andy.
_______________________________________________
aspectj-users mailing list
aspectj-users@...
https://dev.eclipse.org/mailman/listinfo/aspectj-users