Kalle Niemitalo created AVRO-3548:
-------------------------------------
Summary: GenericRecord.GetHashCode returns different values even
when GenericRecord.Equals returns true
Key: AVRO-3548
URL: https://issues.apache.org/jira/browse/AVRO-3548
Project: Apache Avro
Issue Type: Bug
Components: csharp
Affects Versions: 1.11.0
Reporter: Kalle Niemitalo
Attachments: EqualsTest.cs
In the Avro C# library, GenericRecord.Equals(object) returns true if the other
object is a GenericRecord with the same schema and recursively the same field
values. However, GenericRecord.GetHashCode() returns a value that depends on
{{contents.GetHashCode()}}, which in turn depends on the object identity of the
{{object[] contents}} array and not on the values stored in the elements of the
array. Because of that, GenericRecord.GetHashCode() can return different values
even when GenericRecord.Equals returns true. That violates the [requirements
for methods that override
Object.GetHashCode|https://docs.microsoft.com/dotnet/api/system.object.gethashcode?view=netstandard-2.0#notes-to-inheritors].
This breaks the use of GenericRecord as a key in Dictionary<TKey, TValue>.
Applications can work around this bug by defining and using a custom
IEqualityComparer that does not rely on GenericRecord.GetHashCode().
--
This message was sent by Atlassian Jira
(v8.20.7#820007)