[JAVA-1078] Implement equality for java.util.Pattern Created: 15/Jan/14 Updated: 23/Jan/14 Resolved: 21/Jan/14 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Stephen Lee | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Description |
|
BSON that contains a document like
will be translated into a BSONObject object where the value of the field will be an instance of java.util.Pattern, which doesn't implement .equals(). Hence, two logically equivalent BSONObject objects will not considered equal. |
| Comments |
| Comment by Jeffrey Yemin [ 21/Jan/14 ] | |||||||||||||
|
Closing this, but feel free to open an issue about hashCode. | |||||||||||||
| Comment by Jeffrey Yemin [ 21/Jan/14 ] | |||||||||||||
|
If you add
you'll see that equals is working as expected. The problem is that BasicBSONObject does not implement hashCode, so its hashCode method is not consistent with equals. So the driver is violating the contract:
| |||||||||||||
| Comment by Stephen Lee [ 21/Jan/14 ] | |||||||||||||
| |||||||||||||
| Comment by Jeffrey Yemin [ 21/Jan/14 ] | |||||||||||||
|
Can you provide a test for this? Looking at https://github.com/mongodb/mongo-java-driver/blob/master/src/main/org/bson/BasicBSONObject.java#L349-349 it looks like Pattern equality is implemented. |