[JAVA-1090] For embedded $regex, BasicBSONObject hashCode() output is not consistent with equals() Created: 23/Jan/14  Updated: 23/Jan/14  Resolved: 23/Jan/14

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Stephen Lee Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates JAVA-416 Using an Array to create a DBObject b... Closed
Related
is related to JAVA-1078 Implement equality for java.util.Pattern Closed

 Description   

See https://jira.mongodb.org/browse/JAVA-1078?focusedCommentId=485029&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-485029

Revised test case:

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
        BasicBSONObject a = new BasicBSONObject("ts", sdf.parse("2014-01-03T13:16:03.359Z"));
        BasicBSONObject b = new BasicBSONObject("ts", sdf.parse("2014-01-03T13:16:03.359Z"));
        assertTrue(a.equals(b));
        assertTrue(a.hashCode() == b.hashCode());
 
        a = new BasicBSONObject("firstName", Pattern.compile("^asdf"));
        b = new BasicBSONObject("firstName", Pattern.compile("^asdf"));
        assertTrue(a.equals(b));
        assertTrue(a.hashCode() == b.hashCode());



 Comments   
Comment by Jeffrey Yemin [ 23/Jan/14 ]

Thanks Stephen,

After looking at this more carefully, I fixed equals/hashCode in scope of JAVA-416 in a way that will apply for all types: Pattern, array, List, and any types for which there are registered encoding hooks.

Generated at Thu Feb 08 08:53:47 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.