|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
[jira] Created: (AW-478) Recursion during a call aspectOf(instance)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 |
|
|
[jira] Commented: (AW-478) Recursion during a call aspectOf(instance)[ http://jira.codehaus.org/browse/AW-478?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_116046 ] Dmitry Negoda commented on AW-478: ---------------------------------- The patch turned out to be wrong. All we need is to use ReferenceIdentityMap from commons-collections. The m_perInstance should be declared as: protected final Map m_perInstance = new ReferenceIdentityMap(ReferenceIdentityMap.WEAK, ReferenceIdentityMap.HARD); > 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 |
| Free embeddable forum powered by Nabble | Forum Help |