Bug 29850 - [Android] Java.Lang.RuntimeException when popping the last page off the navigation stack.
Summary: [Android] Java.Lang.RuntimeException when popping the last page off the navig...
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 1.4.2
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Seth Rosetter
Depends on:
Reported: 2015-05-07 13:51 UTC by Jon Goldberger [MSFT]
Modified: 2015-07-10 09:32 UTC (History)
3 users (show)

Tags: ac android navigation
Is this bug a regression?: ---
Last known good build:

Test Project (176.81 KB, application/zip)
2015-05-07 13:51 UTC, Jon Goldberger [MSFT]

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 on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Jon Goldberger [MSFT] 2015-05-07 13:51:33 UTC
Created attachment 11122 [details]
Test Project

## Description

When popping the last page off the navigation stack, a Java.Lang.RuntimeException is thrown.

## Steps to reproduce

1. Open the attached test project and restore packages.

2. Deploy Android project to device or simulator

3. Click the Pop Me button

Expected result: As in iOS, nothing will happen.

Actual result: Exception below is thrown

## Notes

Tested with Forms version 1.4.2 and 1.4.3-pre2. Issue occurs on both. 

## Stack trace

> Java.Lang.RuntimeException: java.lang.reflect.InvocationTargetException
>  at --- End of managed exception stack trace ---
>  at java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
>  at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
>  at at dalvik.system.NativeStart.main(Native Method)
>  at Caused by: java.lang.reflect.InvocationTargetException
>  at at java.lang.reflect.Method.invokeNative(Native Method)
>  at at java.lang.reflect.Method.invoke(Method.java:511)
>  at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
>  at ... 2 more
>  at Caused by: md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable: System.NullReferenceException: Object reference not set to an instance of an object
>  at at Xamarin.Forms.NavigationPage.GetHasNavigationBar (Xamarin.Forms.BindableObject) <IL 0x00006, 0x00050>
>  at at Xamarin.Forms.Platform.Android.Platform.ShouldShowActionBarTitleArea () <IL 0x00044, 0x00263>
>  at at Xamarin.Forms.Platform.Android.Platform.PrepareMenu (Android.Views.IMenu) <IL 0x0004c, 0x0034f>
>  at at Xamarin.Forms.Platform.Android.FormsApplicationActivity.OnPrepareOptionsMenu (Android.Views.IMenu) <IL 0x00007, 0x00057>
>  at Android.App.Activity.n_OnPrepareOptionsMenu_Landroid_view_Menu_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.App.Activity.cs:4151
>  at at (wrapper dynamic-method) object.76f67dd5-2010-4933-a15f-f467edc6edcc (intptr,intptr,intptr) <IL 0x00017, 0x0005b>
>  at at md5530bd51e982e6e7b340b73e88efe666e.FormsApplicationActivity.n_onPrepareOptionsMenu(Native Method)
>  at at md5530bd51e982e6e7b340b73e88efe666e.FormsApplicationActivity.onPrepareOptionsMenu(FormsApplicationActivity.java:110)
>  at at android.app.Activity.onPreparePanel(Activity.java:2570)
>  at at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:515)
>  at at com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:896)
>  at at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:281)
>  at at android.view.Choreographer$CallbackRecord.run(Choreographer.java:791)
>  at at android.view.Choreographer.doCallbacks(Choreographer.java:591)
>  at at android.view.Choreographer.doFrame(Choreographer.java:560)
>  at at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:777)
>  at at android.os.Handler.handleCallback(Handler.java:725)
>  at at android.os.Handler.dispatchMessage(Handler.java:92)
>  at at android.os.Looper.loop(Looper.java:175)
>  at at android.app.ActivityThread.main(ActivityThread.java:5279)
>  at ... 5 more

## Environment

=== Xamarin Studio ===

Version 5.9 (build 431)
Installation UUID: 2dc9022f-f9a8-424f-8284-bf224cbbfde0
	Mono 4.0.0 ((detached/d136b79)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400000143

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/apple/Library/Developer/Xamarin/android-sdk-mac_x86
	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)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Apple Developer Tools ===

Xcode 6.3.1 (7703)
Build 6D1002

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 6481535
Branch: master
Build date: 2015-04-27 04:38:13-0400

=== Xamarin.Mac ===

Version: (Business Edition)

=== Build Information ===

Release ID: 509000431
Git revision: 7560726734fc7267de2fa9abed2509968deefaa8
Build date: 2015-04-17 19:25:48-04
Xamarin addins: 2e772c734ab3148054eae7bf8949f340fdeb5e5e

=== Operating System ===

Mac OS X 10.10.3
Darwin Jons-iMac.local 14.3.0 Darwin Kernel Version 14.3.0
    Mon Mar 23 11:59:05 PDT 2015
    root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64
Comment 1 Jon Goldberger [MSFT] 2015-05-07 14:03:13 UTC
As a side note, what is occurring is that a C# NullReferenceException is being propagated to the Java runtime due to the new Cross VM exception propagation in Xamarin Android v. 5.1. So it seems we need a null check here. 

To workaround, check the stack before popping:

>if (Navigation.NavigationStack.Count > 1)
>     await Navigation.PopAsync();
Comment 2 Chris King 2015-05-20 16:52:44 UTC
Indeed. Very nice repro. Non-blocking.
Comment 3 Seth Rosetter 2015-06-25 17:32:10 UTC
Hi all,

I have tested this reproduction with Xamarin.Forms and was able to reproduce the crash. After upgrading to Xamarin.Forms, this crash now longer occurs. Marking as Resolved Fixed.
Comment 4 Parmendra Kumar 2015-07-10 09:32:26 UTC
I have checked this issue with Xamarin.Forms and its working fine.

Hence closing this issue.