[aspectwerkz-dev] [jira] Created: (AW-478) Recursion during a call aspectOf(instance)

"Dmitry Negoda (JIRA)" <jira-yCVjj/[email protected]> Thu, 6 Dec 2007 01:19:57 -0600 (CST)
Newsgroups gmane.comp.java.aspectwerkz.devel
Message-ID <389968.1196925597729.JavaMail.haus-jira@codehaus01.managed.contegix.com>
Recursion during a call aspectOf(instance)
------------------------------------------

                 Key: AW-478
                 URL: http://jira.codehaus.org/browse/AW-478
             Project: AspectWerkz
          Issue Type: Bug
          Components: core
    Affects Versions: 2.0
         Environment: Java 1.5
            Reporter: Dmitry Negoda


When using perInstance aspects and calling aspectOf inside an advise, it calls hashCode() on the instance, which may cause recursive calls to an aspect. AOP should not call any of the instance methods to avoid side-effects. The following AbstractAspectContainer.aspectOf(instance) implementation fixes the problem:

    public Object aspectOf(final Object instance) {
    	Ref ref = new Ref(instance);
        synchronized (m_perInstance) {
            if (!m_perInstance.containsKey(ref)) {
                m_perInstance.put(ref, createAspect());
            }
        }
        return m_perInstance.get(ref);
    }

    static class Ref {
        Object object;
        int hash;
        public int hashCode() { return hash; }
        public boolean equals(Object object) {
            if (object instanceof Ref) {
                return ((Ref)object).object == object;
            } else {
                return false;
            }
        }
        Ref(Object object) {
        	this.object = object;
        	hash = System.identityHashCode(object);
        }
    }



-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email