-
Notifications
You must be signed in to change notification settings - Fork 113
Open
Description
Hi team,
I was going through the code to get familiar and found a bug in RecordType.hashCode().
The equals() method uses Arrays.equals() to compare field names by content but hashCode() passes the fieldNames array directly to Objects.hash() which ends up using the array's identity hash instead of its content. So basically two RecordType instances with the same field names are considered equal but will give different hashcodes which is wrong.
I wrote a small temp test locally as a sanity check:
RecordType rt1 = new RecordType("x", "y", "z");
RecordType rt2 = new RecordType("x", "y", "z");
rt1.equals(rt2) //true
rt1.hashCode() == rt2.hashCode() //false
HashMap<RecordType, String> map = new HashMap<>();
map.put(rt1, "z");
map.get(rt2); //this will return null instead of "z"
The fix is pretty simple: line 68 in RecordType.java just needs to wrap the array.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels