Merge pull request #844 from scottmcarthur/master
authorMarek Safar <marek.safar@gmail.com>
Mon, 13 Jan 2014 14:24:13 +0000 (06:24 -0800)
committerMarek Safar <marek.safar@gmail.com>
Mon, 13 Jan 2014 14:24:13 +0000 (06:24 -0800)
Check for null item in BindingList<T>.InsertItem

mcs/class/System/System.ComponentModel/BindingList.cs
mcs/class/System/Test/System.ComponentModel/BindingListTest.cs

index b64d655efe0fa0b941f2209a056d12609699ecae..b4c0ce8b69b1cb2ba325bf0bd81adaa229b173eb 100644 (file)
@@ -242,7 +242,7 @@ namespace System.ComponentModel {
                        if (raise_list_changed_events)
                                OnListChanged (new ListChangedEventArgs (ListChangedType.ItemAdded, index));
 
-                       if (type_raises_item_changed_events)
+                       if (item != null && type_raises_item_changed_events)
                                (item as INotifyPropertyChanged).PropertyChanged += Item_PropertyChanged;
                }
 
index 88be568f429b51540cf9967c8e84e15cc1864c36..92a6253db915b6bc3d0d3643689b8ae02f134512 100644 (file)
@@ -629,6 +629,16 @@ namespace MonoTests.System.ComponentModel
                        Assert.IsTrue (added, "ItemAdded");
                        Assert.IsTrue (changed, "ItemChanged");
                }
+               
+               [Test] // https://bugzilla.xamarin.com/show_bug.cgi?id=16902
+               public void Bug16902 ()
+               {
+                       var list = new BindingList<Item> ();
+                       list.Insert (0, null);
+                       var count = list.Count;
+                       
+                       Assert.AreEqual (1, count, "1");
+               }
        }
 }