Bug 45281 - App Crashes after sometime with - "JNI DETECTED ERROR IN APPLICATION: use of invalid jobject 0x<Address>"
Summary: App Crashes after sometime with - "JNI DETECTED ERROR IN APPLICATION: use of ...
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 7.0 (C8)
Hardware: PC Windows
: Normal critical
Target Milestone: 7.2 (C10)
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2016-10-11 16:58 UTC by Victor
Modified: 2017-01-10 22:19 UTC (History)
8 users (show)

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


Attachments
LogCat file (1021.56 KB, text/plain)
2016-10-11 17:03 UTC, Victor
Details


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:
Status:
RESOLVED NOT_REPRODUCIBLE

Description Victor 2016-10-11 16:58:47 UTC
# Steps to reproduce
Stay on an UIActivity for more than 2 minutes(turn off Display sleep of the device). App crashes.

# Expected behavior

Should not crash.
# Actual behavior
App crashes with JNI ERROR

# Supplemental info (logs, images, videos)
10-11 23:27:05.352 V/Mono    (15236): _wapi_handle_timedwait_signal_handle: waiting for 0x417 (type Event)
10-11 23:27:05.402 F/art     (15236): art/runtime/java_vm_ext.cc:410] JNI DETECTED ERROR IN APPLICATION: use of invalid jobject 0xdddb50e0
10-11 23:27:05.402 F/art     (15236): art/runtime/java_vm_ext.cc:410]     from void md584ad275774c3f899194d3cd826a71f2b.AndroidGps_GPSClientConnection.n_onLocationChanged(android.location.Location)
10-11 23:27:05.402 F/art     (15236): art/runtime/java_vm_ext.cc:410] "GPS_Thread" prio=5 tid=21 Runnable
10-11 23:27:05.402 F/art     (15236): art/runtime/java_vm_ext.cc:410]   | group="main" sCount=0 dsCount=0 obj=0x12cac160 self=0xd6b39700
10-11 23:27:05.402 F/art     (15236): art/runtime/java_vm_ext.cc:410]   | sysTid=15306 nice=0 cgrp=default sched=0/0 handle=0xd61f5930
10-11 23:27:05.402 F/art     (15236): art/runtime/java_vm_ext.cc:410]   | state=R schedstat=( 669970074 60317385 293 ) utm=56 stm=10 core=1 HZ=100
10-11 23:27:05.402 F/art     (15236): art/runtime/java_vm_ext.cc:410]   | stack=0xd60f3000-0xd60f5000 stackSize=1038KB
10-11 23:27:05.402 F/art     (15236): art/runtime/java_vm_ext.cc:410]   | held mutexes= "mutator lock"(shared held)
10-11 23:27:05.402 F/art     (15236): art/runtime/java_vm_ext.cc:410]   native: #00 pc 0035d069  /system/lib/libart.so (_ZN3art15DumpNativeStackERNSt3__113basic_ostreamIcNS0_11char_traitsIcEEEEiP12BacktraceMapPKcPNS_9ArtMethodEPv+116)
10-11 23:27:05.402 F/art     (15236): art/runtime/java_vm_ext.cc:410]   native: #01 pc 0033ddfd  /system/lib/libart.so (_ZNK3art6Thread4DumpERNSt3__113basic_ostreamIcNS1_11char_traitsIcEEEEP12BacktraceMap+148)
10-11 23:27:05.402 F/art     (15236): art/runtime/java_vm_ext.cc:410]   native: #02 pc 0024fe7b  /system/lib/libart.so (_ZN3art9JavaVMExt8JniAbortEPKcS2_+762)
10-11 23:27:05.402 F/art     (15236): art/runtime/java_vm_ext.cc:410]   native: #03 pc 00250581  /system/lib/libart.so (_ZN3art9JavaVMExt9JniAbortFEPKcS2_z+68)
10-11 23:27:05.402 F/art     (15236): art/runtime/java_vm_ext.cc:410]   native: #04 pc 0033e95b  /system/lib/libart.so (_ZNK3art6Thread13DecodeJObjectEP8_jobject+174)
10-11 23:27:05.402 F/art     (15236): art/runtime/java_vm_ext.cc:410]   native: #05 pc 0031b5d3  /system/lib/libart.so (_ZN3art35InvokeVirtualOrInterfaceWithVarArgsERKNS_33ScopedObjectAccessAlreadyRunnableEP8_jobjectP10_jmethodIDSt9__va_list+270)
10-11 23:27:05.402 F/art     (15236): art/runtime/java_vm_ext.cc:410]   native: #06 pc 0026cc3d  /system/lib/libart.so (_ZN3art3JNI14CallVoidMethodEP7_JNIEnvP8_jobjectP10_jmethodIDz+340)
10-11 23:27:05.402 F/art     (15236): art/runtime/java_vm_ext.cc:410]   native: #07 pc 0000b1c8  /data/app/com.apacheta.TransportACE-1/lib/arm/libmonodroid.so (???)
10-11 23:27:05.402 F/art     (15236): art/runtime/java_vm_ext.cc:410]   at md584ad275774c3f899194d3cd826a71f2b.AndroidGps_GPSClientConnection.n_onLocationChanged(Native method)
10-11 23:27:05.402 F/art     (15236): art/runtime/java_vm_ext.cc:410]   at md584ad275774c3f899194d3cd826a71f2b.AndroidGps_GPSClientConnection.onLocationChanged(AndroidGps_GPSClientConnection.java:59)
10-11 23:27:05.402 F/art     (15236): art/runtime/java_vm_ext.cc:410]   at com.google.android.gms.location.internal.zzk$zzb.handleMessage(unavailable:-1)
10-11 23:27:05.402 F/art     (15236): art/runtime/java_vm_ext.cc:410]   at android.os.Handler.dispatchMessage(Handler.java:102)
10-11 23:27:05.402 F/art     (15236): art/runtime/java_vm_ext.cc:410]   at android.os.Looper.loop(Looper.java:148)
10-11 23:27:05.402 F/art     (15236): art/runtime/java_vm_ext.cc:410]   at android.os.HandlerThread.run(HandlerThread.java:61)
10-11 23:27:05.402 F/art     (15236): art/runtime/java_vm_ext.cc:410] 

# Test environment (full version information)

Testing on Samsung S7 Phone and LG VK810 4G Tablet.			
 Microsoft Visual Studio Professional 2015
Version 14.0.25431.01 Update 3
Microsoft .NET Framework
Version 4.6.01055
Installed Version: Professional
Visual C# 2015   00322-50350-16355-AA612
Microsoft Visual C# 2015

Xamarin   4.2.0.703 (3b7df6f)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   7.0.1.3 (96c7ba6)
Visual Studio extension to enable development for Xamarin.Android.

Xamarin.iOS   10.0.1.10 (ad1cd42)
Visual Studio extension to enable development for Xamarin.iOS.
Comment 1 Victor 2016-10-11 17:03:57 UTC
Created attachment 17982 [details]
LogCat file
Comment 2 Victor 2016-10-13 14:53:33 UTC
There are no issues with Alpha Build - Xamarin.Android 7.0.0.18 (0e59c36)


But an issue in the stable build -  Xamarin.Android   7.0.1.3 (96c7ba6)
Comment 3 Jonathan Pryor 2016-10-17 16:05:35 UTC
we need GREF logs:

https://developer.xamarin.com/guides/android/troubleshooting/troubleshooting/#Global_Reference_Messages

To do so, run:

> $ adb shell setprop debug.mono.log gref,gc

Run your app, and get it to crash.

Next, obtain the GREF log:

> adb shell run-as @PACKAGE_NAME@ cat files/.__override__/grefs.txt > g.txt

Note: @PACKAGE_NAME@ is the package name of your app.

Once you have `g.txt` and the error message from `adb logcat`, determine the missing handle, e.g. in:

> 10-11 23:27:05.402 F/art     (15236): art/runtime/java_vm_ext.cc:410]
> JNI DETECTED ERROR IN APPLICATION: use of invalid jobject 0xdddb50e0

You want the value `0xdddb50e0 `. Search for that value within `g.txt`, and try to trace the handle's lifetime to see where it was disposed.

If it's from a Dispose() call, Don't Do That™.

If there is no Dispose() call, and it's instead collected by the GC, that suggests a Xamarin.Android bug, and we would need a repro and repro instructions.
Comment 4 Remi 2016-10-24 14:16:35 UTC
I have the same issue running my App (Collibris App) from the play store. 
For reproduction you only need to go in the search tab and perform search requests until it crashes (about 3-5 search)

I tried to generate gref logs but my g.txt only contains 
"run-as: Package @PACKAGE_NAME@ is not debuggable"

In Xamarin studio I have all the gref logs so how can I get more infos from that ?
Comment 5 grisha 2016-11-28 15:02:39 UTC
I have very similar issue. It happens when I don't use the application for some hours and then return to it and press one of the buttons inside the application.
The stack trace in my case is:
11-28 16:25:45.848  6816  6816 F art     : art/runtime/java_vm_ext.cc:410] JNI DETECTED ERROR IN APPLICATION: use of invalid jobject 0xce1105a0

11-28 16:25:45.848  6816  6816 F art     : art/runtime/java_vm_ext.cc:410]     from void mono.android.view.View_OnClickListenerImplementor.n_onClick(android.view.View)

11-28 16:25:45.848  6816  6816 F art     : art/runtime/java_vm_ext.cc:410] "main" prio=5 tid=1 Runnable

11-28 16:25:45.848  6816  6816 F art     : art/runtime/java_vm_ext.cc:410]   | group="main" sCount=0 dsCount=0 obj=0x75434fa0 self=0xf4924500

11-28 16:25:45.848  6816  6816 F art     : art/runtime/java_vm_ext.cc:410]   | sysTid=6816 nice=0 cgrp=default sched=0/0 handle=0xf70c1d54

11-28 16:25:45.848  6816  6816 F art     : art/runtime/java_vm_ext.cc:410]   | state=R schedstat=( 16274169378 2804708477 16847 ) utm=1094 stm=533 core=5 HZ=100

11-28 16:25:45.848  6816  6816 F art     : art/runtime/java_vm_ext.cc:410]   | stack=0xff477000-0xff479000 stackSize=8MB

11-28 16:25:45.848  6816  6816 F art     : art/runtime/java_vm_ext.cc:410]   | held mutexes= "mutator lock"(shared held)

11-28 16:25:45.848  6816  6816 F art     : art/runtime/java_vm_ext.cc:410]   native: #00 pc 00371bd7  /system/lib/libart.so (_ZN3art15DumpNativeStackERNSt3__113basic_ostreamIcNS0_11char_traitsIcEEEEiP12BacktraceMapPKcPNS_9ArtMethodEPv+142)

11-28 16:25:45.848  6816  6816 F art     : art/runtime/java_vm_ext.cc:410]   native: #01 pc 00351199  /system/lib/libart.so (_ZNK3art6Thread4DumpERNSt3__113basic_ostreamIcNS1_11char_traitsIcEEEEP12BacktraceMap+160)

11-28 16:25:45.848  6816  6816 F art     : art/runtime/java_vm_ext.cc:410]   native: #02 pc 0025b30b  /system/lib/libart.so (_ZN3art9JavaVMExt8JniAbortEPKcS2_+742)

11-28 16:25:45.848  6816  6816 F art     : art/runtime/java_vm_ext.cc:410]   native: #03 pc 0025ba63  /system/lib/libart.so (_ZN3art9JavaVMExt9JniAbortFEPKcS2_z+74)

11-28 16:25:45.848  6816  6816 F art     : art/runtime/java_vm_ext.cc:410]   native: #04 pc 00351d69  /system/lib/libart.so (_ZNK3art6Thread13DecodeJObjectEP8_jobject+208)

11-28 16:25:45.848  6816  6816 F art     : art/runtime/java_vm_ext.cc:410]   native: #05 pc 0032d8d5  /system/lib/libart.so (_ZN3art35InvokeVirtualOrInterfaceWithVarArgsERKNS_33ScopedObjectAccessAlreadyRunnableEP8_jobjectP10_jmethodIDSt9__va_list+412)

11-28 16:25:45.848  6816  6816 F art     : art/runtime/java_vm_ext.cc:410]   native: #06 pc 002797f3  /system/lib/libart.so (_ZN3art3JNI14CallVoidMethodEP7_JNIEnvP8_jobjectP10_jmethodIDz+354)

11-28 16:25:45.848  6816  6816 F art     : art/runtime/java_vm_ext.cc:410]   native: #07 pc 0000b1c8  /data/app/com.mycompany.mypackage/lib/arm/libmonodroid.so (???)

11-28 16:25:45.848  6816  6816 F art     : art/runtime/java_vm_ext.cc:410]   at mono.android.view.View_OnClickListenerImplementor.n_onClick(Native method)

11-28 16:25:45.848  6816  6816 F art     : art/runtime/java_vm_ext.cc:410]   at mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:30)

11-28 16:25:45.848  6816  6816 F art     : art/runtime/java_vm_ext.cc:410]   at android.view.View.performClick(View.java:5697)

11-28 16:25:45.848  6816  6816 F art     : art/runtime/java_vm_ext.cc:410]   at android.widget.TextView.performClick(TextView.java:10814)

11-28 16:25:45.848  6816  6816 F art     : art/runtime/java_vm_ext.cc:410]   at android.view.View$PerformClick.run(View.java:22526)

11-28 16:25:45.848  6816  6816 F art     : art/runtime/java_vm_ext.cc:410]   at android.os.Handler.handleCallback(Handler.java:739)

11-28 16:25:45.848  6816  6816 F art     : art/runtime/java_vm_ext.cc:410]   at android.os.Handler.dispatchMessage(Handler.java:95)

11-28 16:25:45.848  6816  6816 F art     : art/runtime/java_vm_ext.cc:410]   at android.os.Looper.loop(Looper.java:158)

11-28 16:25:45.848  6816  6816 F art     : art/runtime/java_vm_ext.cc:410]   at android.app.ActivityThread.main(ActivityThread.java:7229)

11-28 16:25:45.848  6816  6816 F art     : art/runtime/java_vm_ext.cc:410]   at java.lang.reflect.Method.invoke!(Native method)

11-28 16:25:45.848  6816  6816 F art     : art/runtime/java_vm_ext.cc:410]   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)

11-28 16:25:45.848  6816  6816 F art     : art/runtime/java_vm_ext.cc:410]   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)



Unfortunately I can reproduce this only on my Samsung device, which means I can't use run-as (as described here http://stackoverflow.com/questions/37413667/run-as-could-not-set-capabilities-operation-not-permitted), so I can't use gref logs. Please advise...
Comment 6 Victor 2017-01-10 22:18:45 UTC
GREF doesn't give much info about the INVALID JOBJECT's life cycle info.

My boss was able to track down the library which was causing the issue.
It is the modernhttpclient library from NuGet.
As Latest Xamarin has it's own version of http library.

By using Xamarin's http library from the latest release for all communications to the server, unable to reproduce this issue.

Thanks for all your support.
Comment 7 Victor 2017-01-10 22:19:44 UTC
As per comment 6