[
https://issues.apache.org/jira/browse/HBASE-3387?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12982861#action_12982861
]
Nicolas Spiegelberg commented on HBASE-3387:
--------------------------------------------
Although the hasCode contract was the original issue that I noticed, a deeper
issue that this is a fundamental violation of equivalence relationships
(http://en.wikipedia.org/wiki/Equivalence_relation ). In particular,
overriding Java functionality for one special class is making Java's equality
operations non-symmetric. For example:
byte[] a = {0,1,2}, b = {0,1,2};
System.out.println( a.equals(b) ); // false
Pair<byte[], byte[]> pa = Pair.newPair(a,a); pb = Pair.newPair(b,b);
System.out.println(pa.equals(pb); // true
System.out.println(pa.getFirst().equals(pb.getFirst()) &&
pa.getSecond().equals(pb.getSecond())); // false
The current equals override makes it such that a == c && b == d is not
symmetric with (a,b) == (c,d).
I understand your problem with needing a deep comparison. However, I think if
you want deep comparisons, you need to take another action other than
overriding a contracted Java API. Example ideas:
1. Use org.apache.hadoop.hbase.util.Bytes.ByteArrayComparator for your
collection's comparator or hand-roll your own.
2. Create a DeepEqual template class that utilizes java.util.Arrays.deepEquals
& deepHashCode. Then create a Pair<DeepEqual<T>, DeepEqual<T>>
However, the Pair class must be refactored to restore its equivalence
relations. The Pair/Tuple class is a well-known idiom and should act the same
here as it does in C++, Python , and other languages.
> Pair does not deep check arrays for equality.
> ----------------------------------------------
>
> Key: HBASE-3387
> URL: https://issues.apache.org/jira/browse/HBASE-3387
> Project: HBase
> Issue Type: Bug
> Components: util
> Affects Versions: 0.90.1
> Environment: Any (discovered in Ubuntu 10.10 using TRUNK).
> Reporter: Jesse Yates
> Priority: Minor
> Fix For: 0.90.1, 0.92.0
>
> Attachments: HBASE-3387.patch
>
> Original Estimate: 0h
> Remaining Estimate: 0h
>
> Pair does not deep check arrays for equality. It merely does x.equals(y) for
> the sent Object. However, with any type of array this is merely going to
> compare the array pointers, rather than the underlying data structure.
> It requires a rewriting of the private equals method in Pair to check for
> elements being an array, then checking the underlying elements.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.