Skip to content

Commit

Permalink
Fix a bug in SearchResultEntry.equals
Browse files Browse the repository at this point in the history
Fixed a bug in the SearchResultEntry.equals method that could
prevent a SearchResultEntry object (which is a subclass of Entry)
from being considered equal to an Entry that is not a
SearchResultEntry.
  • Loading branch information
dirmgr committed Oct 26, 2022
1 parent dd0bf0e commit 3ae2f6d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 16 deletions.
7 changes: 7 additions & 0 deletions docs/release-notes.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ <h3>Version 6.0.7</h3>
</p>

<ul>
<li>
Fixed a bug in the SearchResultEntry.equals method that could prevent a
SearchResultEntry object (which is a subclass of Entry) from being considered
equal to an Entry that is not a SearchResultEntry.
<br><br>
</li>

<li>
Fixed an issue with the Entry.applyModifications method in which it could fail
with a NOT_ALLOWED_ON_RDN result if the provided entry was missing one or more
Expand Down
14 changes: 5 additions & 9 deletions src/com/unboundid/ldap/sdk/SearchResultEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -392,14 +392,8 @@ public Control getControl(@NotNull final String oid)
@Override()
public int hashCode()
{
int hashCode = super.hashCode();

for (final Control c : controls)
{
hashCode += c.hashCode();
}

return hashCode;
// We need this method to satisfy checkstyle.
return super.hashCode();
}


Expand All @@ -424,7 +418,9 @@ public boolean equals(@Nullable final Object o)

if (! (o instanceof SearchResultEntry))
{
return false;
// When comparing a SearchResultEntry with an entry that isn't a
// SearchResultEntry, we'll only rely on the base entry comparison.
return true;
}

final SearchResultEntry e = (SearchResultEntry) o;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,8 +739,7 @@ public void testEqualsIdentity()


/**
* Tests the {@code equals} method with an object that isn't a search result
* entry.
* Tests the {@code equals} method with an object that isn't an entry.
*/
@Test()
public void testEqualsNotEntry()
Expand All @@ -761,10 +760,41 @@ public void testEqualsNotEntry()

SearchResultEntry e = new SearchResultEntry(dn, attributes, controls);

final String nonEntry = "foo";
assertFalse(e.hashCode() == nonEntry.hashCode());
assertFalse(nonEntry.equals(e));
assertFalse(e.equals(nonEntry));
}



/**
* Tests the {@code equals} method with an object that is an equivalent entry
* that is not a search result entry.
*/
@Test()
public void testEqualsEquivalentEntry()
{
String dn = "dc=example,dc=com";

Attribute[] attributes =
{
new Attribute("objectClass", "top", "domain"),
new Attribute("dc", "example"),
};

Control[] controls =
{
new Control("1.2.3.4"),
new Control("1.2.3.5", true, null)
};

SearchResultEntry e = new SearchResultEntry(dn, attributes, controls);

Entry e2 = new Entry(dn, attributes);
assertFalse(e.hashCode() == e2.hashCode());
assertEquals(e.hashCode(), e2.hashCode());
assertTrue(e.equals(e2));
assertTrue(e2.equals(e));
assertFalse(e.equals(e2));
}


Expand All @@ -774,7 +804,7 @@ public void testEqualsNotEntry()
* result entry.
*/
@Test()
public void testEqualsEquivalentEntry()
public void testEqualsEquivalentSearchResultEntry()
{
String dn = "dc=example,dc=com";

Expand Down Expand Up @@ -825,7 +855,7 @@ public void testEqualsDifferentControlCount()

SearchResultEntry e2 = new SearchResultEntry(dn, attributes,
new Control[0]);
assertFalse(e.hashCode() == e2.hashCode());
assertEquals(e.hashCode(), e2.hashCode());
assertFalse(e.equals(e2));
assertFalse(e2.equals(e));
}
Expand Down Expand Up @@ -864,7 +894,7 @@ public void testEqualsDifferentControlContent()
};

SearchResultEntry e2 = new SearchResultEntry(dn, attributes, controls2);
assertFalse(e.hashCode() == e2.hashCode());
assertEquals(e.hashCode(), e2.hashCode());
assertFalse(e.equals(e2));
assertFalse(e2.equals(e));
}
Expand Down

0 comments on commit 3ae2f6d

Please sign in to comment.