Jordan Moore created AVRO-2223:
----------------------------------
Summary: Utf8.equals(String) should pass though to byte comparison
Key: AVRO-2223
URL: https://issues.apache.org/jira/browse/AVRO-2223
Project: Avro
Issue Type: Improvement
Components: java
Affects Versions: 1.8.2, 1.8.1
Reporter: Jordan Moore
Recently when debugging a comparison of two SpecificRecord objects, that we
expected were the exact same, I noticed that one of the objects had the Avro
Utf8 object for a field while the other was just a java.lang.String. So, the
comparison unexpectedly failed when Utf8.equals(java.lang.String) bailed out
immediately rather than continuing on with a proper UTF-8 encoding comparison.
Maybe this is intentional? Equality should be symmetric and thus
java.lang.String.equals(Utf8) would need to return true?
Or is there an alternative to be used for unit testing that doesn't require
altering the schema definition?
Note: We couldn't use compareTo because the schema also has map types, and that
throws the error "maps cannot be compared"
Source code for reference
{code}
public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof Utf8)) return false; // <<----- issue here
Utf8 that = (Utf8)o;
if (!(this.length == that.length)) return false;
byte[] thatBytes = that.bytes;
for (int i = 0; i < this.length; i++)
if (bytes[i] != thatBytes[i])
return false;
return true;
}
{code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)