You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Bob Fields (JIRA)" <ji...@apache.org> on 2008/08/27 16:21:44 UTC

[jira] Created: (LANG-456) HashCodeBuilder throws StackOverflowError in bidirectional navigable association

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


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.


[jira] Commented: (LANG-456) HashCodeBuilder throws StackOverflowError in bidirectional navigable association

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-456?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12633169#action_12633169 ] 

Sebb commented on LANG-456:
---------------------------

Can you provide a simpler test case that works with Java 1.3 and does not require JAXB?

> 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: 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.


[jira] Updated: (LANG-456) HashCodeBuilder throws StackOverflowError in bidirectional navigable association

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-456?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell updated LANG-456:
-------------------------------

    Fix Version/s: 3.0

> 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
>             Fix For: 3.0
>
>         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.


[jira] Updated: (LANG-456) HashCodeBuilder throws StackOverflowError in bidirectional navigable association

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-456?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell updated LANG-456:
-------------------------------

    Comment: was deleted

(was: From LANG-459 - question of whether we should start using IdentityHashMap and removing the IDKey class.

Is the fix here to extend the register concept to all parts of the builder package?)

> 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
>          Components: lang.builder.*
>    Affects Versions: 2.4
>         Environment: Widows XP. Sun JDK 1.5 or 1.6.
>            Reporter: Bob Fields
>             Fix For: 3.0
>
>         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.


[jira] Updated: (LANG-456) HashCodeBuilder throws StackOverflowError in bidirectional navigable association

Posted by "Bob Fields (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-456?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bob Fields updated LANG-456:
----------------------------

    Attachment: HashCodeBuilderStackOverflow.zip

Does anybody even use JDK 1.3 any more? I haven't had it on my machine in years.

Here's an updated version with all the Jaxb stuff removed, built with JDK 1.4.2 with compiler compliance level set to JDK 1.3, that should work for you. There's no dependencies other than commons-lang and JUnit.

> 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.


[jira] Updated: (LANG-456) HashCodeBuilder throws StackOverflowError in bidirectional navigable association

Posted by "Bob Fields (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-456?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bob Fields updated LANG-456:
----------------------------

    Attachment: StackOverflowError.zip

BidirectionalTest demonstrating StackOverflowError when using non-reflection HashCodeBuilder methods.

> 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: 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.


[jira] Commented: (LANG-456) HashCodeBuilder throws StackOverflowError in bidirectional navigable association

Posted by "Bob Fields (JIRA)" <ji...@apache.org>.
    [ 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.


[jira] Commented: (LANG-456) HashCodeBuilder throws StackOverflowError in bidirectional navigable association

Posted by "James Carman (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-456?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12626162#action_12626162 ] 

James Carman commented on LANG-456:
-----------------------------------

Have you tried using UUIDs rather than basing hashCode/equals on "business" fields?

> 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: 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.


[jira] Commented: (LANG-456) HashCodeBuilder throws StackOverflowError in bidirectional navigable association

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-456?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12633948#action_12633948 ] 

Sebb commented on LANG-456:
---------------------------

Thanks for the updated test case which causes the expected stack overflow.

In fact LANG is currently targeted at Java 1.2 - I believe it may be used by Java ME code, which is not so easily upgraded.

==

Since the HashCode for the Bidirectional class depends on the hash code for the JavBVO class and vice versa, it's not surprising that there is a stack overflow.

If you were not using the HashCodeBuider, how would you define the hashcodes?



> 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.


[jira] Commented: (LANG-456) HashCodeBuilder throws StackOverflowError in bidirectional navigable association

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-456?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12791257#action_12791257 ] 

Henri Yandell commented on LANG-456:
------------------------------------

>From LANG-459 - question of whether we should start using IdentityHashMap and removing the IDKey class.

Is the fix here to extend the register concept to all parts of the builder package?

> 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
>             Fix For: 3.0
>
>         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.