Bug 45027 - App crashes when double tapping on ToolbarItem or MenuItem very quickly
Summary: App crashes when double tapping on ToolbarItem or MenuItem very quickly
Status: VERIFIED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Android (show other bugs)
Version: 2.3.2
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-10-04 20:29 UTC by lars6wagner
Modified: 2017-07-05 12:57 UTC (History)
11 users (show)

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


Attachments
Test Project (229.41 KB, application/zip)
2016-10-08 12:07 UTC, lars6wagner
Details
adb logcat log (566.00 KB, text/plain)
2016-10-14 10:35 UTC, lars6wagner
Details
adb logcat log s5 (771.16 KB, text/plain)
2016-10-15 11:14 UTC, lars6wagner
Details
Context Menu crash sample (107.47 KB, application/x-zip-compressed)
2016-11-03 08:20 UTC, Dmitijs Jesilevskis
Details

Description lars6wagner 2016-10-04 20:29:23 UTC
When Android MainActivity derives from FormsAppCompatActivity and an Action is double tapped very quickly the app crashes. It doesn't matter if it's a ToolbarItem or a ViewCell.ContextActions MenuItem.

Thrown Exception (Example from https://www.xamarin.com/prebuilt --> Acquaint):
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
  at System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) [0x00011] in <ea7cbce7a3ab46cf8715badda3a37739>:0
  at System.ThrowHelper.ThrowArgumentOutOfRangeException () [0x00000] in <ea7cbce7a3ab46cf8715badda3a37739>:0
  at System.Collections.Generic.List`1[T].get_Item (System.Int32 index) [0x0000c] in <ea7cbce7a3ab46cf8715badda3a37739>:0
  at Xamarin.Forms.Application+NavigationImpl+<OnPopModal>d__2.MoveNext () [0x0000d] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\Application.cs:302
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <ea7cbce7a3ab46cf8715badda3a37739>:0
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <ea7cbce7a3ab46cf8715badda3a37739>:0
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <ea7cbce7a3ab46cf8715badda3a37739>:0
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <ea7cbce7a3ab46cf8715badda3a37739>:0
  at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in <ea7cbce7a3ab46cf8715badda3a37739>:0
  at Acquaint.XForms.BaseNavigationViewModel+<PopModalAsync>c__async4.MoveNext () [0x00046] in /Users/username/Downloads/app-acquaint-master 2/App/Acquaint.XForms/Acquaint.XForms/ViewModels/BaseNavigationViewModel.cs:57
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <ea7cbce7a3ab46cf8715badda3a37739>:0
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <ea7cbce7a3ab46cf8715badda3a37739>:0
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <ea7cbce7a3ab46cf8715badda3a37739>:0
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <ea7cbce7a3ab46cf8715badda3a37739>:0
  at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in <ea7cbce7a3ab46cf8715badda3a37739>:0
  at Acquaint.XForms.SettingsViewModel+<ExecuteSaveCommand>c__async1.MoveNext () [0x0021a] in /Users/username/Downloads/app-acquaint-master 2/App/Acquaint.XForms/Acquaint.XForms/ViewModels/SettingsViewModel.cs:141
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <ea7cbce7a3ab46cf8715badda3a37739>:0
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <ea7cbce7a3ab46cf8715badda3a37739>:0
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <ea7cbce7a3ab46cf8715badda3a37739>:0
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <ea7cbce7a3ab46cf8715badda3a37739>:0
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <ea7cbce7a3ab46cf8715badda3a37739>:0
  at Acquaint.XForms.SettingsViewModel+<>c__async5.MoveNext () [0x00021] in /Users/username/Downloads/app-acquaint-master 2/App/Acquaint.XForms/Acquaint.XForms/ViewModels/SettingsViewModel.cs:53
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <ea7cbce7a3ab46cf8715badda3a37739>:0
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>m__0 (System.Object state) [0x00000] in <ea7cbce7a3ab46cf8715badda3a37739>:0
  at Android.App.SyncContext+<Post>c__AnonStorey0.<>m__0 () [0x00000] in <de8603109e284ddbb9bdf88cbec24e9f>:0
  at Java.Lang.Thread+RunnableImplementor.Run () [0x0000b] in <de8603109e284ddbb9bdf88cbec24e9f>:0
  at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <de8603109e284ddbb9bdf88cbec24e9f>:0
  at at (wrapper dynamic-method) System.Object:b2e090dc-1b4e-47d1-82de-b358633bc0d8 (intptr,intptr)
Comment 1 Ashley Gazich [MSFT] 2016-10-07 21:52:25 UTC
Thank you for submitting this report! Please include the following to help us begin investigation:

1. Minimized runnable test case demonstrating the issue
2. Steps to reproduce
3. Full version information from Xamarin Studio > About Xamarin Studio > Show Details > Copy Information [button]

Thank you,
Xamarin Support
Comment 2 lars6wagner 2016-10-08 12:07:59 UTC
Created attachment 17945 [details]
Test Project
Comment 3 lars6wagner 2016-10-08 12:08:13 UTC
1. Added Test-Project
2. Open Application on Android --> Press long on a ListView item so that the NavigationActionBar appears --> DoubleTap quickly the MORE menuitem
3. 
Xamarin Studio Community
Version 6.1.1 (build 15)
Installation UUID: 1d637eed-308f-4396-b3e5-57fcb60d3472
Runtime:
	Mono 4.6.1 (mono-4.6.0-branch-c8sr0/abb06f1) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 406010005

NuGet
Version: 3.4.3.0

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

Apple Developer Tools
Xcode 8.0 (11246)
Build 8A218a

Xamarin.Android
Version: 7.0.1.3 (Xamarin Studio Community)
Android SDK: /Users/testuser/Library/Android/sdk
	Supported Android versions:
		4.0.3 (API level 15)
		4.4   (API level 19)
		5.0   (API level 21)
		6.0   (API level 23)

SDK Tools Version: 24.3.4
SDK Platform Tools Version: 23.0.1
SDK Build Tools Version: 23.0.1

Java SDK: /usr
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

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

Xamarin Android Player
Not Installed

Xamarin.iOS
Version: 10.0.1.10 (Xamarin Studio Community)
Hash: ad1cd42
Branch: cycle8-sr0-xi
Build date: 2016-10-03 15:18:44-0400

Xamarin.Mac
Version: 2.10.0.105 (Xamarin Studio Community)

Build Information
Release ID: 601010015
Git revision: fa52f02641726146e2589ed86ec4097fbe101888
Build date: 2016-09-22 08:03:02-04
Xamarin addins: 75d65712af93d54dc39ae4c42b21dfa574859fd6
Build lane: monodevelop-lion-cycle8-sr0

Operating System
Mac OS X 10.12.0
Darwin NB.local 16.0.0 Darwin Kernel Version 16.0.0
    Mon Aug 29 17:56:20 PDT 2016
    root:xnu-3789.1.32~3/RELEASE_X86_64 x86_64
Comment 4 Ashley Gazich [MSFT] 2016-10-11 21:34:58 UTC
May I ask whether you are testing on device and/or emulator and the respective API levels? 
Could you please attach the adb logcat logs https://developer.xamarin.com/guides/cross-platform/troubleshooting/questions/version-logs/#Xamarin_Studio_Mac?

I am unable to produce a crash using the sample and repro steps on a Samsung Galaxy S5 API 23 and Xamarin Studio

=== Xamarin Studio Enterprise ===

Version 6.1.1 (build 15)
Installation UUID: 3bf0795e-4e95-43d1-847f-d23b467050f6
Runtime:
	Mono 4.6.1 (mono-4.6.0-branch-c8sr0/ef43c15) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 406010005

=== NuGet ===

Version: 3.4.3.0

=== Xamarin.Profiler ===

Not Installed

=== Xamarin.Android ===

Version: 7.0.1.3 (Xamarin Enterprise)
Android SDK: /Users/ashleyg/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		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)

SDK Tools Version: 25.2.2
SDK Platform Tools Version: 24.0.3
SDK Build Tools Version: 24.0.3

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

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

=== Xamarin Android Player ===

Not Installed

=== Apple Developer Tools ===

Xcode 7.3.1 (10188.1)
Build 7D1014

=== Xamarin.iOS ===

Version: 10.0.1.10 (Xamarin Enterprise)
Hash: ad1cd42
Branch: cycle8-sr0-xi
Build date: 2016-10-03 15:18:44-0400

=== Xamarin.Mac ===

Version: 2.10.0.105 (Xamarin Enterprise)

=== Build Information ===

Release ID: 601010015
Git revision: fa52f02641726146e2589ed86ec4097fbe101888
Build date: 2016-09-22 08:03:02-04
Xamarin addins: 75d65712af93d54dc39ae4c42b21dfa574859fd6
Build lane: monodevelop-lion-cycle8-sr0

=== Operating System ===

Mac OS X 10.11.6
Darwin ashleyg.local 15.6.0 Darwin Kernel Version 15.6.0
    Mon Aug 29 20:21:34 PDT 2016
    root:xnu-3248.60.11~1/RELEASE_X86_64 x86_64
Comment 5 lars6wagner 2016-10-14 10:34:57 UTC
Yeah sure. I'm testing on a Wiko Highway Pure Android Version 5.0.2. But if required I can test it on further Android devices.

I attached the adb logcat log.
Comment 6 lars6wagner 2016-10-14 10:35:27 UTC
Created attachment 18047 [details]
adb logcat log
Comment 7 lars6wagner 2016-10-15 11:14:38 UTC
Just tested it on a Samsung Galaxy S5 and there is the same problem (see adb logs).
Comment 8 lars6wagner 2016-10-15 11:14:58 UTC
Created attachment 18054 [details]
adb logcat log s5
Comment 9 lars6wagner 2016-10-25 17:16:42 UTC
Could you verify the problem?
Comment 10 Dmitijs Jesilevskis 2016-11-02 07:44:46 UTC
We are experiencing the same issues.
Test devices: Huawei P9, Samsung Galaxy A5.
Compile using Android version: Android 7.0 (Nougat)
Minimum Andorid to target: API Level 16

Referenced libraries: 
* Xamarin.Forms (2.3.2.127)
* Xamarin.Android.Support.v7.* (23.3.0)


Suspect that:
* Error happens in Android 's CellAdapter class, OnActionItemClickedImpl method (https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.Android/CellAdapter.cs#L250)
* Action variable might be destroyed by the time second tap processing attempt starts


Extracted the following stack trace:
Time	Device Name	Type	PID	Tag	Message
11-01 19:05:25.061	Samsung SM-A510F	Error	32507	mono-rt	[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object.
11-01 19:05:23.331	Samsung SM-A510F	Info	30076	Quasar	start to send events
11-01 19:05:23.261	Samsung SM-A510F	Debug	32507	Mono	Probing 'java_interop_jnienv_throw'.
11-01 19:05:23.261	Samsung SM-A510F	Debug	32507	Mono	DllImport searching in: '__Internal' ('(null)').
11-01 19:05:23.261	Samsung SM-A510F	Debug	32507	Mono	Searching for 'java_interop_jnienv_throw'.
11-01 19:05:23.261	Samsung SM-A510F	Debug	32507	Mono	Found as 'java_interop_jnienv_throw'.
11-01 19:05:23.251	Samsung SM-A510F	Warning	32507	art	JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable
11-01 19:05:23.131	Samsung SM-A510F	Info	32507	MonoDroid	  at Android.Support.V7.View.ActionMode+ICallbackInvoker.n_OnActionItemClicked_Landroid_support_v7_view_ActionMode_Landroid_view_MenuItem_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_mode, System.IntPtr native_item) [0x00019] in <c690702816034f28aca512af1f0abd66>:0 
11-01 19:05:23.131	Samsung SM-A510F	Info	32507	MonoDroid	  at Xamarin.Forms.Platform.Android.CellAdapter.global::Android.Support.V7.View.ActionMode.ICallback.OnActionItemClicked (Android.Support.V7.View.ActionMode mode, Android.Views.IMenuItem item) [0x00000] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\CellAdapter.cs:90 
11-01 19:05:23.131	Samsung SM-A510F	Info	32507	MonoDroid	System.NullReferenceException: Object reference not set to an instance of an object.
11-01 19:05:23.131	Samsung SM-A510F	Info	32507	MonoDroid	  at Xamarin.Forms.Platform.Android.CellAdapter.OnActionItemClickedImpl (Android.Views.IMenuItem item) [0x00007] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\CellAdapter.cs:253 
11-01 19:05:23.131	Samsung SM-A510F	Info	32507	MonoDroid	  at (wrapper dynamic-method) System.Object:d143ebbc-a5b7-4800-b2af-560595e533f5 (intptr,intptr,intptr,intptr)
11-01 19:05:23.121	Samsung SM-A510F	Info	32507	MonoDroid	UNHANDLED EXCEPTION:
Comment 11 Ashley Gazich [MSFT] 2016-11-02 22:27:43 UTC
@lars @ Dmitijs Jesilevskis
Could you test with Xamarin.Forms 2.3.3.163-pre3?


I am still unable to reproduce a crash on device, but finally reproduced with the original test case as-is and an accelerated emulator (x86, API 23). 
However, after updating to Xamarin.Forms 2.3.3.163-pre3, I am unable to reproduce a crash on emulator or device. 


### Results

System.NullReferenceException: Object reference not set to an instance of an object.
  at Xamarin.Forms.Platform.Android.CellAdapter.OnActionItemClickedImpl (Android.Views.IMenuItem item) [0x00007] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\CellAdapter.cs:253
  at Xamarin.Forms.Platform.Android.CellAdapter.global::Android.Support.V7.View.ActionMode.ICallback.OnActionItemClicked (Android.Support.V7.View.ActionMode mode, Android.Views.IMenuItem item) [0x00000] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\CellAdapter.cs:90
  at Android.Support.V7.View.ActionMode+ICallbackInvoker.n_OnActionItemClicked_Landroid_support_v7_view_ActionMode_Landroid_view_MenuItem_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_mode, System.IntPtr native_item) [0x00019] in <c690702816034f28aca512af1f0abd66>:0
  at at (wrapper dynamic-method) System.Object:856f457d-3c6f-4ed6-854a-78fc22d118f2 (intptr,intptr,intptr,intptr)


### Application Output & adb logcat logs
https://microsoft-my.sharepoint.com/personal/asgazi_microsoft_com/_layouts/15/guestaccess.aspx?guestaccesstoken=2%2f%2fSncer7c1PktV7js2%2bO6vIjkQ0KUD6q2Et1%2fnGYzg%3d&folderid=2_1b9021b1b00264558996e3e9afdb10531&rev=1
Comment 12 Dmitijs Jesilevskis 2016-11-03 08:20:45 UTC
Created attachment 18313 [details]
Context Menu crash sample

The issue is still there with XF 2.3.3.163-pre3.
Attaching upgraded sample project.

1. Run app;
2. Navigate to 'ListView Test' page;
3. Long-tap any of the list items;
4. Double-tap 'Delete' option in context menu.
Comment 13 lars6wagner 2016-11-06 11:18:14 UTC
Same here, issue still there with XF 2.3.3.166-pre4

Used attached Test Project with the following steps:
1. Run app
2. Long touch on "speaker"
3. Double tap "MORE" quickly
4. App crashes
Comment 14 adrianknight89 2016-12-05 07:10:12 UTC
@lars I fixed your issue. See https://github.com/xamarin/Xamarin.Forms/pull/609

You also mentioned ToolbarItem. If you have a repro for that too, please post it here.
Comment 15 lars6wagner 2016-12-06 17:14:50 UTC
Thank you very much! Will look into this as soon as a nuget pkg is available. No, it was just for the ContextAction on Android.
Comment 16 Rui Marinho 2017-02-13 13:54:32 UTC
Should be fixed on 2.3.5-pre1
Comment 17 Saurabh Paunikar 2017-07-05 12:57:27 UTC
Verified on Xamarin.form version 2.3.5.256-pre6 Issue is not getting reproduced.
Hence marking it as verified

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