Bug 59896 - v2.4.0: Adding inserting section to ListView causes crash IF first section is empty
Summary: v2.4.0: Adding inserting section to ListView causes crash IF first section is...
Status: CONFIRMED
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS (show other bugs)
Version: 2.4.0
Hardware: Macintosh Mac OS
: Normal major
Target Milestone: ---
Assignee: Bugzilla
URL:
: 60177 (view as bug list)
Depends on:
Blocks:
 
Reported: 2017-10-02 14:58 UTC by Ben Askren
Modified: 2017-10-20 11:16 UTC (History)
8 users (show)

See Also:
Tags: listview, section, ac
Is this bug a regression?: Yes
Last known good build:


Attachments

Description Ben Askren 2017-10-02 14:58:42 UTC
== Issue Description
As of Xamain.Forms version 2.4.0, inserting a new section to a ListView in an iOS app causes the app to crash.  This does not happen in earlier versions of Xamarin.Forms.

== Demo project:
https://github.com/baskren/ListViewUpdate

== Steps to replicate
1. Download, build, and run demo project
2. Click the "Add Group between A & C" button.  An exception is thrown at line 508 in Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.UpdateItems.
3. In the ListViewUpdate.iOS project, change the package version of Xamarin.Forms to any 2.3.4 version.
4. Clean, build, and run the demo project.
5. Success!

== Arch chair analysis
In version 2.4.0, Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.UpdateItems was changed to check if the e.NewStartingIndex and e.OldStartingIndex was greater than the native UITableView's number of rows in the section.

		void UpdateItems(NotifyCollectionChangedEventArgs e, int section, bool resetWhenGrouped)
		{
			var exArgs = e as NotifyCollectionChangedEventArgsEx;
			if (exArgs != null)
				_dataSource.Counts[section] = exArgs.Count;

			var groupReset = resetWhenGrouped && Element.IsGroupingEnabled;

			var lastIndex = Control.NumberOfRowsInSection(section);
			if (e.NewStartingIndex > lastIndex || e.OldStartingIndex > lastIndex)
				throw new ArgumentException(
					$"Index '{Math.Max(e.NewStartingIndex, e.OldStartingIndex)}' is greater than the number of rows '{lastIndex}'.");

That being said, in the demo project (all 2.3.4 and 2.4.0 versions of XF), the UpdateItems call is made using section parameter = 0 even though section 0 is not the section with updated items (it is the root of the collection that had the change, not section 0).  Why this is happening?  If it helps get this fixed faster, I'll be happy to look into this.

== System Enviroment
=== Visual Studio Community 2017 for Mac ===

Version 7.1.5 (build 2)
Installation UUID: c3c61da2-4d87-4c39-b8d3-9fbf7e6af430
Runtime:
	Mono 5.2.0.224 (d15-3/14f2c81) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 502000224

=== NuGet ===

Version: 4.3.0.2418

=== .NET Core ===

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

=== Xamarin.Profiler ===

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

=== Apple Developer Tools ===

Xcode 9.0 (13247)
Build 9A235

=== Xamarin.Mac ===

Version: 3.6.3.3 (Visual Studio Community)

=== Xamarin.Android ===

Version: 7.4.5.1 (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: 11.0.0.0 (Visual Studio Community)
Hash: 152b654a
Branch: xcode9
Build date: 2017-09-15 02:25:56-0400

=== Xamarin Inspector ===

Version: 1.3.1
Hash: cbc48dd
Branch: 1.3-release
Build date: Thu, 21 Sep 2017 19:52:53 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 701050002
Git revision: 7afedcaef8e7542e70e3cf8f9bdb26938b8c0876
Build date: 2017-09-15 08:39:58-04
Xamarin addins: 3262aadf811a18c12eac6742532d052b0139a808
Build lane: monodevelop-lion-d15-3-xcode9

=== Operating System ===

Mac OS X 10.12.6
Darwin 16.7.0 Darwin Kernel Version 16.7.0
    Thu Jun 15 17:36:27 PDT 2017
    root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64
Comment 1 Paul DiPietro [MSFT] 2017-10-02 16:36:03 UTC
Reproduction project was acting up but putting the code into a fresh project reproduces the behavior.
Comment 2 Paul DiPietro [MSFT] 2017-10-13 13:48:24 UTC
*** Bug 60177 has been marked as a duplicate of this bug. ***

Note You need to log in before you can comment on or make changes to this bug.