Bug 177678 - equality of joinpoints
Summary: equality of joinpoints
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Runtime (show other bugs)
Version: 1.5.3   Edit
Hardware: PC Windows XP
: P3 critical (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL: http://arno@blogger.de
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-03-15 18:41 EDT by Arno Schmidmeier CLA
Modified: 2007-03-20 07:33 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Arno Schmidmeier CLA 2007-03-15 18:41:39 EDT
I recognized following problem, while writing some aspects for easy creation of mocks.
Sometimes the static parts of two joinpoints do not equal, even if they were captured from the same joinpoints. (e.g. by an before after and around advice).

After a short look in the codebase of staticpart, I recognized that there is no equals method defined there. 

So my naïve suggestion would be to overwrite the equals method, relying on an equivalence of the toString() method.
This would conclude that also the .hashcode must be overwritten. This method could simply retrun the hascode of the toString() method.

My second suggestions would be to cache the result of the toString method in this class, if the creation of the toString method is expensive. 

If you would be interested in a patch following one or the other approach please let me know.

Cheers 
   Arno Schmidmeier

http:://www.aspectsoft.com
blog: arno@blogger.de
Comment 1 Matthew Webster CLA 2007-03-16 06:42:17 EDT
There has been a lengthy discussion on this subject http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg06808.html and there are two enhancements as well: Bug 89009 "Add ability to associate user object to join point" and Bug 160296 "Custom JoinPoint factory".

The issue of staticpart equality has been raised before (http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg06926.html) but I don't quite understand your problem. Can you post an example?

Comment 2 Arno Schmidmeier CLA 2007-03-18 03:25:03 EDT
The problem seems to be:
-that joinPointStaticPart does not implement the equals method
-and that multiple staticJoinpoint-objects for each Joinpoint might created, if several aspects advice the same join point. 

So my naive suggestion would look like 

//written without a compiler at hand.

public boolean equals(Object target){
if (target==null)
    return false;
if (target instanceof thisJoinPointStaticPart)
    return (toString().equals(target.toString()));
return super(target);
}

//required by some Java Specification
public integer hashcode(){
   return toString().hashcode();
}
Comment 3 Matthew Webster CLA 2007-03-20 07:33:00 EDT
(In reply to comment #2)
> The problem seems to be:
> -that joinPointStaticPart does not implement the equals method
> -and that multiple staticJoinpoint-objects for each Joinpoint might created, if
> several aspects advice the same join point. 

As I said in the aspectj-users discussion JoinPoint.StaticPart instances are transient singletons created and managed by AspectJ (in fact by code generated by the weaver). You should never get 2 instances of an object that represents a join point so there should be no reason to compare them. 

The situation is different for JoinPoint instances.