Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-456

HashCodeBuilder throws StackOverflowError in bidirectional navigable association

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Reopened
    • Major
    • Resolution: Unresolved
    • 2.4
    • None
    • lang.builder.*
    • None
    • Widows XP. Sun JDK 1.5 or 1.6.

    Description

      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.

      Attachments

        1. StackOverflowError.zip
          14 kB
          Bob Fields
        2. LANG-456-patch.txt
          7 kB
          Woonsan Ko
        3. HashCodeBuilderStackOverflow.zip
          18 kB
          Bob Fields
        4. 0001-LANG-456-HashCodeBuilder-throws-StackOverflowError-i.patch
          6 kB
          Bruno P. Kinoshita

        Issue Links

          Activity

            People

              Unassigned Unassigned
              bob fields Bob Fields
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated: