[ 
https://issues.apache.org/jira/browse/LANG-456?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12634175#action_12634175
 ] 

Bob Fields commented on LANG-456:
---------------------------------

The other builder methods (toString, compare, equals) specifically check for 
recursive behavior and prevent a StackOverflow.

We use HashCodeBuilder globally on all ValueObjects generated by templates 
using AndroMDA www.andromda.org. Right now I check for the recursive 
relationship in the model and remove one side of the relationship from the 
HashCodeBuilder generated code output. That defaults to the hashCode for all 
attributes (except the recursive one on one side) plus the hashCode of the 
ancestor.

> HashCodeBuilder throws StackOverflowError in bidirectional navigable 
> association
> --------------------------------------------------------------------------------
>
>                 Key: LANG-456
>                 URL: https://issues.apache.org/jira/browse/LANG-456
>             Project: Commons Lang
>          Issue Type: Bug
>    Affects Versions: 2.4
>         Environment: Widows XP. Sun JDK 1.5 or 1.6.
>            Reporter: Bob Fields
>         Attachments: HashCodeBuilderStackOverflow.zip, StackOverflowError.zip
>
>
> This is not the reflection methods, it is the regular HashCodeBuilder append 
> methods. It causes EqualsBuilder, ToStringBuilder, CompareToBuilder to also 
> throw the StackOverflowException, but those methods work when one of the 
> HashCodeBuilder bidirectional association attributes .hashCode() is commented 
> out. The problem is that all of the builders call registerObject() which 
> creates a hashCode, but only the reflectionAppend method checks if an object 
> is registered.
> Bi-directional associations are a very common pattern in Jaxb and Hibernate. 
> In this case, I generate code from a model in order to avoid the reflection 
> penalty - I already know what the attributes are at compile time, so I use 
> .append instead of .reflectionAppend.
> See attached example + unit test. One side of the bidirectional association 
> must be commented out in the hashCode method.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to