Bug 44129 - [Forms Android] Removing and adding items to TabbedPage BindingContext ObservableCollection crashes the app
Summary: [Forms Android] Removing and adding items to TabbedPage BindingContext Observ...
Status: VERIFIED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Android (show other bugs)
Version: 2.3.2
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-09-08 22:07 UTC by Jani Lirkki
Modified: 2016-10-18 14:13 UTC (History)
5 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Sample app for reproducing "TabbedPage remove and add items with MvvmLight" crash (50.19 KB, application/x-zip-compressed)
2016-09-08 22:07 UTC, Jani Lirkki
Details
Sample app for reproducing "TabbedPage remove and add items to BindingContext ObservableCollection" crash (51.37 KB, application/x-zip-compressed)
2016-09-09 09:38 UTC, Jani Lirkki
Details

Description Jani Lirkki 2016-09-08 22:07:46 UTC
Created attachment 17385 [details]
Sample app for reproducing "TabbedPage remove and add items with MvvmLight" crash

Overview:

    App crashes when removing tabs and adding new tab through TabbedPage BindingContext

Steps to Reproduce: 

    1) Start the attached sample app
    2) Switch to second tab
    3) Press "CRASH ME" -button

Actual Results:

    App crashes because of "Java.Lang.IndexOutOfBoundsException: Invalid index 0, size is 0"

Expected Results:

    App doesn't crash. It should behave the same way as it behaves now when "CRASH ME"-button is pressed on first tab.

Additional Information:

    - Note that "CRASH ME" -button on first tab doesn't crash the app. Only on second tab.
    - Happens both with and without AppCompat. The sample app doesn't use AppCompat.
    - Seems that doesn't crash if MvvmLight not used for property setting.
    - Xamarin Forms version 2.3.2.118-pre1

Crash Dump from output window:

    UNHANDLED EXCEPTION:
    Java.Lang.IndexOutOfBoundsException: Invalid index 0, size is 0
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 
      at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (JniObjectReference instance, JniObjectReference type, Java.Interop.JniMethodInfo method) [0x000a6] in /Users/builder/data/lanes/3540/1cf254db/source/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.g.cs:12062 
      at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (IntPtr jobject, IntPtr jclass, IntPtr jmethod) [0x00000] in /Users/builder/data/lanes/3540/1cf254db/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:438 
      at Android.Support.V4.View.PagerAdapter.NotifyDataSetChanged () [0x00079] in <filename unknown>:0 
      at Xamarin.Forms.Platform.Android.AppCompat.TabbedPageRenderer.OnChildrenCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x0002e] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\TabbedPageRenderer.cs:251 
      at (wrapper delegate-invoke) <Module>:invoke_void_object_NotifyCollectionChangedEventArgs (object,System.Collections.Specialized.NotifyCollectionChangedEventArgs)
      at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00012] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/System/compmod/system/collections/objectmodel/observablecollection.cs:288 
      at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (NotifyCollectionChangedAction action, System.Object item, Int32 index) [0x00000] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/System/compmod/system/collections/objectmodel/observablecollection.cs:351 
      at System.Collections.ObjectModel.ObservableCollection`1[T].InsertItem (Int32 index, System.Collections.ObjectModel.T item) [0x00024] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/System/compmod/system/collections/objectmodel/observablecollection.cs:219 
      at System.Collections.ObjectModel.Collection`1[T].Insert (Int32 index, System.Collections.ObjectModel.T item) [0x00038] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/collections/objectmodel/collection.cs:103 
      at Xamarin.Forms.MultiPage`1[T].OnTemplatedItemsChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x000b5] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\MultiPage.cs:220 
      at Xamarin.Forms.TemplatedItemsList`2[TView,TItem].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x0000a] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\TemplatedItemsList.cs:757 
      at Xamarin.Forms.TemplatedItemsList`2[TView,TItem].OnProxyCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e, Boolean fixWindows) [0x00471] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\TemplatedItemsList.cs:1100 
      at Xamarin.Forms.TemplatedItemsList`2[TView,TItem].OnProxyCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00000] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\TemplatedItemsList.cs:954 
      at Xamarin.Forms.ListProxy.OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x0000a] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\ListProxy.cs:230 
      at Xamarin.Forms.ListProxy+<>c__DisplayClass32_0.<OnCollectionChanged>b__0 () [0x00018] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\ListProxy.cs:203 
      at Xamarin.Forms.ListProxy.OnCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x000a0] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\ListProxy.cs:222 
      at Xamarin.Forms.ListProxy+WeakNotifyProxy.OnCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00031] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\ListProxy.cs:386 
      at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00012] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/System/compmod/system/collections/objectmodel/observablecollection.cs:288 
      at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (NotifyCollectionChangedAction action, System.Object item, Int32 index) [0x00000] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/System/compmod/system/collections/objectmodel/observablecollection.cs:351 
      at System.Collections.ObjectModel.ObservableCollection`1[T].InsertItem (Int32 index, System.Collections.ObjectModel.T item) [0x00024] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/System/compmod/system/collections/objectmodel/observablecollection.cs:219 
      at System.Collections.ObjectModel.Collection`1[T].Add (System.Collections.ObjectModel.T item) [0x00023] in /Users/builder/data/lanes/3540/1cf254db/source/mono/external/referencesource/mscorlib/system/collections/objectmodel/collection.cs:67 
      at XF_TabbedPage_MvvmLight_Crash.MainPage.UpdateDate_Click (System.Object sender, System.EventArgs e) [0x00017] in C:\Users\lirkkjan\Documents\Xamarin\XF_TabbedPage_MvvmLight_Crash\XF_TabbedPage_MvvmLight_Crash\XF_TabbedPage_MvvmLight_Crash\MainPage.xaml.cs:17 
      at Xamarin.Forms.Button.Xamarin.Forms.IButtonController.SendClicked () [0x00020] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\Button.cs:123 
      at Xamarin.Forms.Platform.Android.AppCompat.ButtonRenderer+ButtonClickListener.OnClick (Android.Views.View v) [0x0000b] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\ButtonRenderer.cs:291 
      at Android.Views.View+IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (IntPtr jnienv, IntPtr native__this, IntPtr native_v) [0x00011] in /Users/builder/data/lanes/3540/1cf254db/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.View.cs:1806 
      at (wrapper dynamic-method) System.Object:6d62e1bc-277f-4f57-a8c7-b3448b510df1 (intptr,intptr,intptr)
      --- End of managed Java.Lang.IndexOutOfBoundsException stack trace ---

    Unhandled Exception:
    Java.Lang.IndexOutOfBoundsException: Invalid index 0, size is 0
      at (wrapper dynamic-method) System.Object:6d62e1bc-277f-4f57-a8c7-b3448b510df1 (intptr,intptr,intptr)
      at (wrapper native-to-managed) System.Object:6d62e1bc-277f-4f57-a8c7-b3448b510df1 (intptr,intptr,intptr)
      --- End of managed Java.Lang.IndexOutOfBoundsException stack trace ---
    java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
        at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
        at java.util.ArrayList.get(ArrayList.java:308)
        at android.support.design.widget.TabLayout.getTabAt(TabLayout.java:518)
        at android.support.design.widget.TabLayout$TabLayoutOnPageChangeListener.onPageSelected(TabLayout.java:1986)
        at android.support.v4.view.ViewPager.dispatchOnPageSelected(ViewPager.java:1862)
        at android.support.v4.view.ViewPager.scrollToItem(ViewPager.java:629)
        at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:609)
        at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:570)
        at android.support.v4.view.ViewPager.dataSetChanged(ViewPager.java:1019)
        at android.support.v4.view.ViewPager$PagerObserver.onChanged(ViewPager.java:2991)
        at android.support.v4.view.PagerAdapter.notifyDataSetChanged(PagerAdapter.java:279)
        at md5270abb39e60627f0f200893b490a1ade.ButtonRenderer_ButtonClickListener.n_onClick(Native Method)
        at md5270abb39e60627f0f200893b490a1ade.ButtonRenderer_ButtonClickListener.onClick(ButtonRenderer_ButtonClickListener.java:30)
        at android.view.View.performClick(View.java:4780)
        at android.view.View$PerformClick.run(View.java:19866)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5254)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Comment 1 Jani Lirkki 2016-09-09 09:38:20 UTC
Created attachment 17393 [details]
Sample app for reproducing "TabbedPage remove and add items to BindingContext ObservableCollection" crash

Simplified sample app that doesn't depend on MvvmLight.
Comment 2 Jani Lirkki 2016-09-21 07:36:53 UTC
Still reproducible in latest Xamarin Forms prerelease version 2.3.3.152-pre2.
Comment 3 Samantha Houts [MSFT] 2016-10-12 21:59:51 UTC
Should be fixed in 2.3.3-pre3. Thank you!
Comment 4 Parmendra Kumar 2016-10-18 14:13:38 UTC
I have checked this issue with Xamarin.Forms 2.3.3-pre3 and observed that this issue has been fixed.

Hence closing this issue.

Thanks.

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