Commons Lang
  1. Commons Lang
  2. LANG-606

EqualsBuilder causes StackOverflowException

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.5
    • Fix Version/s: 3.0
    • Component/s: lang.builder.*
    • Labels:
      None

      Description

      EqualsBuilder causes StackOverflowException when comparing objects with cyclical object references.

      e,g.
      static class TestObjectReference {
      @SuppressWarnings("unused")
      private TestObjectReference reference;
      @SuppressWarnings("unused")
      private TestObject one;

      public TestObjectReference(int one)

      { this.one = new TestObject(one); }

      public void setObjectReference(
      TestObjectReference reference)

      { this.reference = reference; }

      @Override
      public boolean equals(Object obj)

      { return EqualsBuilder.reflectionEquals(this, obj); }

      }

        Activity

        Hide
        Oliver Sauder added a comment -

        Attached patch should solve the issue.

        I've used the same attempt used in HashCodeBuilder solving the cyclical reference issue.

        Only difference is that a registry with objects pairs is used. When checking if two objects have already be compared resp. registered those two objects need to be swapped as the cyclical reference takes place when "the other object" is the "this object".

        Show
        Oliver Sauder added a comment - Attached patch should solve the issue. I've used the same attempt used in HashCodeBuilder solving the cyclical reference issue. Only difference is that a registry with objects pairs is used. When checking if two objects have already be compared resp. registered those two objects need to be swapped as the cyclical reference takes place when "the other object" is the "this object".
        Hide
        Henri Yandell added a comment -

        Can you check the patch? It doesn't apply cleanly, but neither file in question has changed since you posted the patch.

        Show
        Henri Yandell added a comment - Can you check the patch? It doesn't apply cleanly, but neither file in question has changed since you posted the patch.
        Hide
        Oliver Sauder added a comment -

        Strange. I created the patch with svn diff > EqualsBuilderCyclicalObjectReferences.patch. When I then reverted all files (svn revert -R .) and tried to apply the patch it did not apply cleanly on my system either.
        After some research I found out that I probably hit a subversion bug (http://subversion.tigris.org/issues/show_bug.cgi?id=2164).

        Well to workaround this problem instead of using svn diff I used the old fashion but working diff utility.

        This patch now applies cleanly with the command patch -p1 -i EqualsBuilderCyclicalObjectReferences-v01.patch.

        Show
        Oliver Sauder added a comment - Strange. I created the patch with svn diff > EqualsBuilderCyclicalObjectReferences.patch. When I then reverted all files (svn revert -R .) and tried to apply the patch it did not apply cleanly on my system either. After some research I found out that I probably hit a subversion bug ( http://subversion.tigris.org/issues/show_bug.cgi?id=2164 ). Well to workaround this problem instead of using svn diff I used the old fashion but working diff utility. This patch now applies cleanly with the command patch -p1 -i EqualsBuilderCyclicalObjectReferences-v01.patch.
        Hide
        Henri Yandell added a comment -

        Thanks Oliver.

        I modified the @since tags, but otherwise committed as is.

        svn ci -m "Applying the copy of the HashCodeBuilder code to stop cyclic references over to EqualsBuilder per LANG-606 and Oliver Sauder's patch" src/
        Sending src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java
        Sending src/test/java/org/apache/commons/lang3/builder/EqualsBuilderTest.java
        Transmitting file data ..
        Committed revision 925671.

        Show
        Henri Yandell added a comment - Thanks Oliver. I modified the @since tags, but otherwise committed as is. svn ci -m "Applying the copy of the HashCodeBuilder code to stop cyclic references over to EqualsBuilder per LANG-606 and Oliver Sauder's patch" src/ Sending src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java Sending src/test/java/org/apache/commons/lang3/builder/EqualsBuilderTest.java Transmitting file data .. Committed revision 925671.

          People

          • Assignee:
            Unassigned
            Reporter:
            Oliver Sauder
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development