Details
-
Improvement
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
1.8.1, 1.8.2
-
None
-
None
Description
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
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; }