cushon / issues-import

0 stars 0 forks source link

Array processing using Objects.equal() and Objects.hashCode() #221

Closed cushon closed 9 years ago

cushon commented 9 years ago

Original issue created by gintas@google.com on 2013-12-10 at 10:41 AM


I just hit a bug where an array was being processed using Guava's Objects.equal(a, b) and Objects.hashCode(...). The former defers to .equals(), and the latter defers to Arrays.equal(varargs), so if one of the arguments is an array by itself, it will be compared by reference rather than by content.

I think there is already a check for comparing arrays using .equals(), but it doesn't seem to pick up the equivalent Guava calls.

Example of bad code:

int[] a = {1, 2, 3} int badHash = Objects.hashCode(a); int[] b = {1, 2, 3} boolean badEquals = Objects.equal(a, b);

cushon commented 9 years ago

Original comment posted by eaftan@google.com on 2014-02-10 at 08:00 PM


I committed the ArrayHashCode check and am about to turn it on for Google. That check catches .hashCode(), the Java 7 java.util.Objects hashcode methods, and the Guava com.google.common.base.Objects hashcode methods.

I had thought that the ArrayEquals check also caught the Guava methods, but it doesn't. Thanks for pointing it out. I'll add that.


Status: Accepted

cushon commented 9 years ago

Original comment posted by eaftan@google.com on 2014-02-10 at 08:01 PM


(No comment entered for this change.)


Owner: eaftan@google.com

cushon commented 9 years ago

Original comment posted by eaftan@google.com on 2014-03-04 at 01:01 AM


Fixed in rev c2405fb35807.


Status: Fixed