From: E.Z. Hart Date: Mon, 4 Nov 2019 21:21:59 +0000 (-0700) Subject: Add missing null check on ItemsSource when IsGrouped is true; fixes #8269 (#8273) X-Git-Tag: accepted/tizen/5.5/unified/20200421.150457~81^2~1^2~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dfc32f9205ebf3fd93bacdebcee03c32ae5e9c42;p=platform%2Fcore%2Fcsapi%2Fxsf.git Add missing null check on ItemsSource when IsGrouped is true; fixes #8269 (#8273) --- 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)); }