[Mono-bugs] [Bug 579791] New: HashSet<T> does not handle null values when using a non-default comparer

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sat Feb 13 12:05:11 EST 2010


http://bugzilla.novell.com/show_bug.cgi?id=579791

http://bugzilla.novell.com/show_bug.cgi?id=579791#c0


           Summary: HashSet<T> does not handle null values when using a
                    non-default comparer
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.6.x
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Critical
          Priority: P5 - None
         Component: CORLIB
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: tagdev at gmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


Created an attachment (id=342347)
 --> (http://bugzilla.novell.com/attachment.cgi?id=342347)
Test to reproduce the bug.

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.3)
Gecko/20090824 Firefox/3.5.3 GTB6 (.NET CLR 3.5.30729)

This patch is for System.Collections.Generic.HashSet<T> to fix the error shown
at the bottom, which happens when you create a hash-set with a non-default
comparer like StringComparer.Ordinal and then attempt to populate it with a
null value.  The hash-set should always be able to store null values (for
data-types that allow them), even if the underlying comparer behaves according
to spec (i.e., throws an ArgumentNullException from
IEqualityComparer<T>.GetHashCode for nulls).  The solution is simply to bypass
the comparer whenever a null value is encountered.

Reproducible: Always

Steps to Reproduce:
Apply the HastSetTest patch and run the test named
TestNullsWithComparerThrowingException.
Actual Results:  
Exception is thrown.

Expected Results:  
No exception -- hash-set should handle null like any other value.

See message titled "[PATCH] Fix HashSet<T> when used with nulls and non-default
comparer" started on 11 Feb 2010 at mono-devel-list.

-----

Example exception...

[System.ArgumentNullException]: Argument cannot be null.
Parameter name: s
at System.OrdinalComparer.GetHashCode (string) <0x00066> at
System.Collections.Generic.HashSet`1<string>.GetItemHashCode (string) <0x00033>
at System.Collections.Generic.HashSet`1<string>.Add (string) <0x00016> at
System.Collections.Generic.HashSet`1<string>..ctor
(System.Collections.Generic.IEnumerable`1<string>,System.Collections.Generic
IEqualityComparer`1<string>) <0x000e4>
at
MyClass.MyMethodThatCreatesTheHashSetFromDataContainingTheNullStringAndUsing
StringComparerOrdinal (string) <0x00214>

-- 
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list