From dfc32f9205ebf3fd93bacdebcee03c32ae5e9c42 Mon Sep 17 00:00:00 2001 From: "E.Z. Hart" Date: Mon, 4 Nov 2019 14:21:59 -0700 Subject: [PATCH] Add missing null check on ItemsSource when IsGrouped is true; fixes #8269 (#8273) --- .../Issue8269.cs | 49 ++++++++++++++++++++++ .../Xamarin.Forms.Controls.Issues.Shared.projitems | 1 + .../CollectionView/ItemsSourceFactory.cs | 4 +- 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue8269.cs diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue8269.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue8269.cs new file mode 100644 index 0000000..00788ce --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue8269.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + +#if UITEST +using Xamarin.Forms.Core.UITests; +using Xamarin.UITest; +using NUnit.Framework; +#endif + +namespace Xamarin.Forms.Controls.Issues +{ +#if UITEST + [Category(UITestCategories.CollectionView)] +#endif + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Github, 8269, "[Bug] CollectionView exception when IsGrouped=true and null ItemSource", + PlatformAffected.Android)] + public class Issue8269 : TestContentPage + { + const string Success = "Success"; + + protected override void Init() + { + var layout = new StackLayout(); + + var instructions = new Label { Text = "If this page has not crashed, the test is sucessful." }; + var success = new Label { AutomationId = Success, Text = Success }; + + var cv = new CollectionView { ItemsSource = null, IsGrouped = true }; + + layout.Children.Add(success); + layout.Children.Add(instructions); + layout.Children.Add(cv); + + Content = layout; + } + +#if UITEST + [Test] + public void IsGroupedWithNullItemsSourceShouldNotCrash() + { + RunningApp.WaitForElement(Success); + } +#endif + } +} diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index 60ac858..5822171 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -96,6 +96,7 @@ Issue7803.xaml + diff --git a/Xamarin.Forms.Platform.Android/CollectionView/ItemsSourceFactory.cs b/Xamarin.Forms.Platform.Android/CollectionView/ItemsSourceFactory.cs index a03fe0a..9cbd965 100644 --- a/Xamarin.Forms.Platform.Android/CollectionView/ItemsSourceFactory.cs +++ b/Xamarin.Forms.Platform.Android/CollectionView/ItemsSourceFactory.cs @@ -37,7 +37,9 @@ namespace Xamarin.Forms.Platform.Android public static IGroupableItemsViewSource Create(GroupableItemsView itemsView, RecyclerView.Adapter adapter) { - if (itemsView.IsGrouped) + var source = itemsView.ItemsSource; + + if (itemsView.IsGrouped && source != null) { return new ObservableGroupedSource(itemsView, new AdapterNotifier(adapter)); } -- 2.7.4