Bug 5033 - ApiDemo fails on API14+ when using Notifications
Summary: ApiDemo fails on API14+ when using Notifications
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 4.1.x
Hardware: Macintosh Mac OS
: --- critical
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2012-05-11 12:47 UTC by Chris Hardy [MSFT]
Modified: 2012-05-11 13:46 UTC (History)
2 users (show)

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

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 Chris Hardy [MSFT] 2012-05-11 12:47:20 UTC
Crash when using notifications in an the APIDemo app: ApiDemo > App > Service > Local Service Controller > Start Service -> Crashes


E/mono    (30980): WARNING: The runtime version supported by this application is unavailable.
E/mono    (30980): Using default runtime: v2.0.50727
I/monodroid-gc(30980): environment supports jni NewWeakGlobalRef
W/monodroid-gc(30980): GREF GC Threshold: 46800
I/mono    (30980): Stacktrace:
I/mono    (30980): 
I/mono    (30980):   at Android.Runtime.JNIEnv.DeleteLocalRef (intptr) <0x0003f>
I/mono    (30980):   at Android.App.Notification..ctor (int,string,long) <0x003cb>
I/mono    (30980):   at MonoDroid.ApiDemo.LocalService.ShowNotification () <0x000f3>
I/mono    (30980):   at MonoDroid.ApiDemo.LocalService.OnCreate () <0x0007b>
I/mono    (30980):   at Android.App.Service.n_OnCreate (intptr,intptr) <0x00033>
I/mono    (30980):   at (wrapper dynamic-method) object.9b9e1bb7-9800-4629-bf2f-3ea2d38615a7 (intptr,intptr) <0x0002b>
I/mono    (30980):   at (wrapper native-to-managed) object.9b9e1bb7-9800-4629-bf2f-3ea2d38615a7 (intptr,intptr) <0xffffffff>
I/MonoDroid(30980): UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
I/MonoDroid(30980): at Android.Runtime.JNIEnv.DeleteLocalRef (intptr) <0x0003f>
I/MonoDroid(30980): at Android.App.Notification..ctor (int,string,long) <0x003cb>
I/MonoDroid(30980): at MonoDroid.ApiDemo.LocalService.ShowNotification () <0x000f3>
I/MonoDroid(30980): at MonoDroid.ApiDemo.LocalService.OnCreate () <0x0007b>
I/MonoDroid(30980): at Android.App.Service.n_OnCreate (intptr,intptr) <0x00033>
I/MonoDroid(30980): at (wrapper dynamic-method) object.9b9e1bb7-9800-4629-bf2f-3ea2d38615a7 (intptr,intptr) <0x0002b>
E/mono    (30980): 
E/mono    (30980): Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object
E/mono    (30980):   at Android.Runtime.JNIEnv.DeleteLocalRef (IntPtr jobject) [0x00000] in <filename unknown>:0 
E/mono    (30980):   at Android.App.Notification..ctor (Int32 icon, System.String tickerText, Int64 when) [0x00000] in <filename unknown>:0 
E/mono    (30980):   at MonoDroid.ApiDemo.LocalService.ShowNotification () [0x00000] in <filename unknown>:0 
E/mono    (30980):   at MonoDroid.ApiDemo.LocalService.OnCreate () [0x00000] in <filename unknown>:0 
E/mono    (30980):   at Android.App.Service.n_OnCreate (IntPtr jnienv, IntPtr native__this) [0x00000] in <filename unknown>:0 
E/mono    (30980):   at (wrapper dynamic-method) object:9b9e1bb7-9800-4629-bf2f-3ea2d38615a7 (intptr,intptr)
Comment 1 Jonathan Pryor 2012-05-11 13:26:12 UTC
Fixed in master/1cdec7d4 and 4.2-series/bb1beee2.
Comment 2 PJ 2012-05-11 13:31:04 UTC
This feature has a normal crash. See bug 3865, look for 'service'. Pressing start and stop local service can always crash (and does with the Android API Demo).
Comment 3 Jonathan Pryor 2012-05-11 13:41:32 UTC
@PJ: Different bug. This bug is wrt Local Service Controller, which from #3865 is:

        * Local Service Controller
            * Start service: http://screencast.com/t/HKGxrtChZg

The above image doesn't show a crash. What it does show is a notification message in the lower-right corner saying "Local service has started."

For #5033, the issue is that when Local Service Controller > Start Service was tapped, the process would die. Not the emulator, the process. Full logcat output would contain:

> JNI WARNING: 0x40f8e008 is not a valid JNI reference
>              in Lmonodroid/apidemo/LocalService;.n_onCreate:()V (DeleteLocalRef)
> "main" prio=5 tid=1 RUNNABLE
>   | group="main" sCount=0 dsCount=0 obj=0x409c1460 self=0x12810
>   | sysTid=1064 nice=0 sched=0/0 cgrp=default handle=1074082952
>   | schedstat=( 19522896095 11880895033 9605 ) utm=1854 stm=98 core=0
>   at monodroid.apidemo.LocalService.n_onCreate(Native Method)
> Stacktrace:
>   at Android.Runtime.JNIEnv.DeleteLocalRef (intptr) <0x0003f>
>   at Android.App.Notification..ctor (int,string,long) <0x003cb>
>   at MonoDroid.ApiDemo.LocalService.ShowNotification () <0x000f3>
>   at MonoDroid.ApiDemo.LocalService.OnCreate () <0x0007b>

Which clearly contains a JNI warning about an invalid JNI reference.

Further note that this would only occur on API14+ devices. This does not crash on e.g. my N1 (2.3.3) or my Xoom (3.2.1). I have no idea which Android version the screenshot came from.