[ldap-sdk-commits] SF.net SVN: ldap-sdk:[1575] trunk
A Java-based LDAP API
Brought to you by:
dirmgr,
kennethleo
From: <di...@us...> - 2022-10-26 22:14:17
|
Revision: 1575 http://sourceforge.net/p/ldap-sdk/code/1575 Author: dirmgr Date: 2022-10-26 22:14:15 +0000 (Wed, 26 Oct 2022) Log Message: ----------- Fix a bug in SearchResultEntry.equals 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. Modified Paths: -------------- trunk/docs/release-notes.html trunk/src/com/unboundid/ldap/sdk/SearchResultEntry.java trunk/tests/unit/src/com/unboundid/ldap/sdk/SearchResultEntryTestCase.java Modified: trunk/docs/release-notes.html =================================================================== --- trunk/docs/release-notes.html 2022-10-20 21:55:30 UTC (rev 1574) +++ trunk/docs/release-notes.html 2022-10-26 22:14:15 UTC (rev 1575) @@ -14,6 +14,13 @@ <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 attribute values used in its RDN. Modified: trunk/src/com/unboundid/ldap/sdk/SearchResultEntry.java =================================================================== --- trunk/src/com/unboundid/ldap/sdk/SearchResultEntry.java 2022-10-20 21:55:30 UTC (rev 1574) +++ trunk/src/com/unboundid/ldap/sdk/SearchResultEntry.java 2022-10-26 22:14:15 UTC (rev 1575) @@ -392,14 +392,8 @@ @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(); } @@ -424,7 +418,9 @@ 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; Modified: trunk/tests/unit/src/com/unboundid/ldap/sdk/SearchResultEntryTestCase.java =================================================================== --- trunk/tests/unit/src/com/unboundid/ldap/sdk/SearchResultEntryTestCase.java 2022-10-20 21:55:30 UTC (rev 1574) +++ trunk/tests/unit/src/com/unboundid/ldap/sdk/SearchResultEntryTestCase.java 2022-10-26 22:14:15 UTC (rev 1575) @@ -739,8 +739,7 @@ /** - * 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() @@ -761,10 +760,41 @@ 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)); } @@ -774,7 +804,7 @@ * result entry. */ @Test() - public void testEqualsEquivalentEntry() + public void testEqualsEquivalentSearchResultEntry() { String dn = "dc=example,dc=com"; @@ -825,7 +855,7 @@ 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)); } @@ -864,7 +894,7 @@ }; 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)); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |