From: Jb Evain Date: Wed, 29 Jun 2011 23:24:50 +0000 (+0200) Subject: Fix handling of null in the non generic implementation of EqualityComparer. Fixes... X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=648425ebe1af72b062b1810e86ada260be9104f0;p=mono.git Fix handling of null in the non generic implementation of EqualityComparer. Fixes 703027. --- diff --git a/mcs/class/corlib/System.Collections.Generic/EqualityComparer.cs b/mcs/class/corlib/System.Collections.Generic/EqualityComparer.cs index bb09fa183d4..a60f3001b5f 100644 --- a/mcs/class/corlib/System.Collections.Generic/EqualityComparer.cs +++ b/mcs/class/corlib/System.Collections.Generic/EqualityComparer.cs @@ -45,7 +45,6 @@ namespace System.Collections.Generic { _default = new DefaultComparer (); } - public abstract int GetHashCode (T obj); public abstract bool Equals (T x, T y); @@ -59,11 +58,23 @@ namespace System.Collections.Generic { int IEqualityComparer.GetHashCode (object obj) { + if (obj == null) + return 0; + + if (!(obj is T)) + throw new ArgumentException ("Argument is not compatible", "obj"); + return GetHashCode ((T)obj); } bool IEqualityComparer.Equals (object x, object y) { + if (x == y) + return true; + + if (x == null || y == null) + return false; + if (!(x is T)) throw new ArgumentException ("Argument is not compatible", "x"); if (!(y is T))