Bug 57561 - Crash when Listview with GroupHeaderTemplate set to a DataTemplateSelector has no members
Summary: Crash when Listview with GroupHeaderTemplate set to a DataTemplateSelector ha...
Status: CONFIRMED
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.4
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL: https://github.com/baskren/EmptyGroup
Depends on:
Blocks:
 
Reported: 2017-06-16 15:59 UTC by Ben Askren
Modified: 2017-07-12 22:51 UTC (History)
2 users (show)

Tags: ac android listview grouping groupheadertemplate DataTemplateSelector
Is this bug a regression?: No
Last known good build:


Attachments
Demo Solution (122.48 KB, application/zip)
2017-06-16 15:59 UTC, Ben Askren
Details
repro project (50.59 KB, application/x-zip-compressed)
2017-06-20 21:30 UTC, Jimmy [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 57561 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description Ben Askren 2017-06-16 15:59:30 UTC
Created attachment 22948 [details]
Demo Solution

*** PROBLEM DESCRIPTION ***

Android version of a Xamarin.Forms app with a ListView with its GroupHeaderTemplate set to a DataTemplateSelector will crash when an ItemsSource group has no member objects.




*** HOW TO REPLICATE ***

1) Download demo VisualStudio solution from https://github.com/baskren/EmptyGroup.  (Note: you may likely have to remove and reinstall the Xamarin.Forms packages from each project because of the directory structure I'm using in my dev environment). 

2) Run on iOS and Android to verify it works.

3) Comment out line 14 in EmptyGroup/EmptyGroup.cs

  BEFORE:

            var deluxGroup = new StringGroup("French Cheeses")
            {
                "Bleu d'Auvergne", "Brie de Meaux"  // If this line is commented out, app will crash on Android (but not iOS)
            };

  AFTER:

            var deluxGroup = new StringGroup("French Cheeses")
            {
                //"Bleu d'Auvergne", "Brie de Meaux"  // If this line is commented out, app will crash on Android (but not iOS)
            };

4) Run on iOS (it should work).  Run on Android (it crashes).




*** ANALYSIS AND COMMENTS **

Digging into the Xamarin.Forms source, I'm guessing that Xamarin.Forms/Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs is the most likely culprit.  Specifically, what the ```GetItemType(int position)``` method does when ```_listView.IsGroupingEnabled``` and it's time to process a group header.  By the time it gets to line 151 (2.3.4-2 branch), it should have used ```position``` and ```TemplatedItemsView.TemplatedItems.GetGroupIndexFromGlobal(position, out row);``` to figure out that this row is the group header row and be working on selecting a template to match the group type.  Instead, it appears it's looking for the type of a group member.

Or at least this is my guess.  I would confirm but the last time I built Xamarin.Forms from source, it took a couple of days to get the environment just right.  I'm betting that isn't the case for you and you could fix this issue much faster than that ;-)




*** BUILD ENVIRONMENT ***

=== Visual Studio Community 2017 for Mac ===

Version 7.0.1 (build 24)
Installation UUID: c3c61da2-4d87-4c39-b8d3-9fbf7e6af430
Runtime:
	Mono 5.0.1.1 (2017-02/5077205) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 500010001

=== NuGet ===

Version: 4.0.0.2323

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
SDK: /usr/local/share/dotnet/sdk/1.0.3/Sdks
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.0.1/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.5.4
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 8.3.3 (12175.1)
Build 8E3004b

=== Xamarin.Mac ===

Version: 3.4.0.36 (Visual Studio Community)

=== Xamarin.Android ===

Version: 7.3.1.2 (Visual Studio Community)
Android SDK: /Users/ben/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
		5.1    (API level 22)
		6.0    (API level 23)
		7.0    (API level 24)
		7.1    (API level 25)

SDK Tools Version: 26.0.2
SDK Platform Tools Version: 25.0.6
SDK Build Tools Version: 25.0.3

Java SDK: /usr
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin.iOS ===

Version: 10.10.0.36 (Visual Studio Community)
Hash: d2270eec
Branch: d15-2
Build date: 2017-05-22 16:30:53-0400

=== Xamarin Inspector ===

Version: 1.2.2
Hash: b71b035
Branch: d15-1
Build date: Fri, 21 Apr 2017 17:57:12 GMT

=== Build Information ===

Release ID: 700010024
Git revision: 7ab1ca2ced6f584e56b7a0d4d321d00775cd95c9
Build date: 2017-05-19 05:44:51-04
Xamarin addins: 08d17158f3365beee5e60f67999e607cce4b3f93
Build lane: monodevelop-lion-d15-2

=== Operating System ===

Mac OS X 10.12.5
Darwin 16.6.0 Darwin Kernel Version 16.6.0
    Fri Apr 14 16:21:16 PDT 2017
    root:xnu-3789.60.24~6/RELEASE_X86_64 x86_64
Comment 1 Ben Askren 2017-06-16 16:00:33 UTC
I forgot to add a link to a github repository with the demo project:

https://github.com/baskren/EmptyGroup
Comment 2 Jimmy [MSFT] 2017-06-20 21:30:31 UTC
Created attachment 23023 [details]
repro project

Thank you for filing this report! I was able to reproduce the issue on Android with the project provided. I've attached an updated project with fixed package reference paths for easier testing and I am confirming the report so the team can investigate further.

Crash stack trace: https://gist.github.com/jimmgarrido/599441836f8e6f36663e07ab285bfa6f


### Version Tests
2.3.6.112   BAD
2.3.5-pre3  BAD
2.3.4.247   BAD