[Mono-bugs] [Bug 80563][Nor] New - Arrays cast to ICollection`1 can't handle Contains(null).

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Fri Jan 19 17:51:22 EST 2007


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by felipe.lessa at gmail.com.

http://bugzilla.ximian.com/show_bug.cgi?id=80563

--- shadow/80563	2007-01-19 17:51:22.000000000 -0500
+++ shadow/80563.tmp.850	2007-01-19 17:51:22.000000000 -0500
@@ -0,0 +1,101 @@
+Bug#: 80563
+Product: Mono: Class Libraries
+Version: 1.2
+OS: 
+OS Details: Ubuntu Linux Edgy Eft 6.10
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: CORLIB
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: felipe.lessa at gmail.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Arrays cast to ICollection`1 can't handle Contains(null).
+
+Description of Problem:
+
+If you take an array and cast it to a generic ICollection, you can call its
+Contains() method with a null parameter (if the type is a reference type,
+of course). Unfortunately, a strange exception is thrown instead.
+
+Steps to reproduce the problem:
+1. Compile the program attached below with gmcs.
+2. Run with mono.
+
+Actual Results:
+
+False
+False
+System.NullReferenceException: Object reference not set to an instance of
+an object
+  at System.Array.InternalArray__ICollection_Contains[Object]
+(System.Object item) [0x00033] in
+/tmp/scratch/BUILD/mono-1.2.2.1/mcs/class/corlib/System/Array.cs:90 
+  at (wrapper managed-to-managed)
+System.Object[]:System.Collections.Generic.ICollection`1.Contains (object)
+  at Tester.Test () [0x00000] 
+True
+System.NullReferenceException: Object reference not set to an instance of
+an object
+  at System.Array.InternalArray__ICollection_Contains[Object]
+(System.Object item) [0x00033] in
+/tmp/scratch/BUILD/mono-1.2.2.1/mcs/class/corlib/System/Array.cs:90 
+  at (wrapper managed-to-managed)
+System.Object[]:System.Collections.Generic.ICollection`1.Contains (object)
+  at Tester.Test () [0x00000] 
+False
+
+
+Expected Results:
+False
+False
+True
+True
+False
+False
+
+How often does this happen?
+Always. I tested the attached program with Mono 1.1.17.1 bundled in Ubuntu
+6.10 and with Mono 1.2.2.1_1 from the downloads section. The traceback
+above was seen when using the latter version.
+
+Additional Information:
+
+using System;
+using System.Collections.Generic;
+
+public class Tester {
+	static ICollection<object> test;
+
+	public static void Main() {
+		test = new List<object>();
+		Test();
+
+		test = new object[] {};
+		Test();
+
+		test = new object[] {null};
+		Test();
+
+		test = new List<object>(test);
+		Test();
+		
+		test = new object[] {new object()};
+		Test();
+
+		test = new List<object>(test);
+		Test();
+	}
+
+	public static void Test() {
+		try {
+			Console.WriteLine(test.Contains(null));
+		} catch (Exception e) {
+			Console.WriteLine(e);
+		}
+	}
+}


More information about the mono-bugs mailing list