Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24012] Android: crashing trying to load non-existing JS resources inside native modules

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2016-10-12T19:56:02.000+0000
Affected Version/sRelease 6.0.0
Fix Version/sRelease 6.0.0
ComponentsAndroid, Hyperloop
Labelsqe-6.0.0
ReporterJosh Longton
AssigneeChristopher Williams
Created2016-10-10T19:49:46.000+0000
Updated2018-08-06T17:49:24.000+0000

Description

Attempting to load a JS resource that does not exist underneath a native nodule will result in Android crashing. This is most obvious using Hyperloop where paths are generated like require('hyperloop/android.content.Intent') under the hood. We then attempt to load 'android.content.Intent' as a JS resource inside the native hyperloop module. Using proper paths like: require('/hyperloop/android.com.Intent') works around this issue, but doesn't address the root bug. This bug appears to be an existing issue, not a regression.

Steps to reproduce:

Import the hyperloop example application [here](https://github.com/appcelerator/hyperloop-examples).

Or use the app.js below.

app.js

{noformat} var Intent = require('android.content.Intent'); var intent = Ti.Android.createIntent(); var nativeIntent = new Intent(intent); // Fails {noformat}

Actual

{noformat} [INFO] : TiRootActivity: (main) [0,0] checkpoint, on root activity create, savedInstanceState: null [INFO] : art: art/runtime/java_vm_ext.cc:410] JNI DETECTED ERROR IN APPLICATION: obj == null [INFO] : art: art/runtime/java_vm_ext.cc:410] in call to CallObjectMethodV [INFO] : art: art/runtime/java_vm_ext.cc:410] from void org.appcelerator.kroll.runtime.v8.V8Runtime.nativeRunModule(java.lang.String, java.lang.String, org.appcelerator.kroll.KrollProxySupport) [INFO] : art: art/runtime/java_vm_ext.cc:410] "main" prio=5 tid=1 Runnable [INFO] : art: art/runtime/java_vm_ext.cc:410] | group="main" sCount=0 dsCount=0 obj=0x73b922a0 self=0xf4e76500 [INFO] : art: art/runtime/java_vm_ext.cc:410] | sysTid=10996 nice=0 cgrp=default sched=0/0 handle=0xf7028b34 [INFO] : art: art/runtime/java_vm_ext.cc:410] | state=R schedstat=( 523465687 16614272 137 ) utm=41 stm=10 core=4 HZ=100 [INFO] : art: art/runtime/java_vm_ext.cc:410] | stack=0xff616000-0xff618000 stackSize=8MB [INFO] : art: art/runtime/java_vm_ext.cc:410] | held mutexes= "mutator lock"(shared held) [INFO] : art: art/runtime/java_vm_ext.cc:410] native: #00 pc 0035a55f /system/lib/libart.so (_ZN3art15DumpNativeStackERNSt3__113basic_ostreamIcNS0_11char_traitsIcEEEEiPKcPNS_9ArtMethodEPv+126) [INFO] : art: art/runtime/java_vm_ext.cc:410] native: #01 pc 0033b0e7 /system/lib/libart.so (_ZNK3art6Thread4DumpERNSt3__113basic_ostreamIcNS1_11char_traitsIcEEEE+138) [INFO] : art: art/runtime/java_vm_ext.cc:410] native: #02 pc 0024dfcb /system/lib/libart.so (_ZN3art9JavaVMExt8JniAbortEPKcS2_+750) [INFO] : art: art/runtime/java_vm_ext.cc:410] native: #03 pc 0024e6d3 /system/lib/libart.so (_ZN3art9JavaVMExt9JniAbortFEPKcS2_z+62) [INFO] : art: art/runtime/java_vm_ext.cc:410] native: #04 pc 0027d48f /system/lib/libart.so (_ZN3art3JNI17CallObjectMethodVEP7_JNIEnvP8_jobjectP10_jmethodIDSt9__va_list+458) [INFO] : art: art/runtime/java_vm_ext.cc:410] native: #05 pc 002c2839 /data/app/com.appc.intents-1/lib/arm/libkroll-v8.so (_ZN7_JNIEnv16CallObjectMethodEP8_jobjectP10_jmethodIDz+28) [INFO] : art: art/runtime/java_vm_ext.cc:410] native: #06 pc 002c4c57 /data/app/com.appc.intents-1/lib/arm/libkroll-v8.so (_ZN8titanium13KrollBindings25getExternalCommonJsModuleERKN2v820FunctionCallbackInfoINS1_5ValueEEE+458) [INFO] : art: art/runtime/java_vm_ext.cc:410] native: #07 pc 003b73e4 /data/app/com.appc.intents-1/lib/arm/libkroll-v8.so (_ZN2v88internal25FunctionCallbackArguments4CallEPFvRKNS_20FunctionCallbackInfoINS_5ValueEEEE+136) [INFO] : art: art/runtime/java_vm_ext.cc:410] native: #08 pc 00407dec /data/app/com.appc.intents-1/lib/arm/libkroll-v8.so (???) [INFO] : art: art/runtime/java_vm_ext.cc:410] native: #09 pc 0040845c /data/app/com.appc.intents-1/lib/arm/libkroll-v8.so (???) [INFO] : art: art/runtime/java_vm_ext.cc:410] native: #10 pc 00000098 (???) [INFO] : art: art/runtime/java_vm_ext.cc:410] at org.appcelerator.kroll.runtime.v8.V8Runtime.nativeRunModule(Native method) [INFO] : art: art/runtime/java_vm_ext.cc:410] at org.appcelerator.kroll.runtime.v8.V8Runtime.doRunModule(V8Runtime.java:196) [INFO] : art: art/runtime/java_vm_ext.cc:410] at org.appcelerator.kroll.KrollRuntime.runModule(KrollRuntime.java:241) [INFO] : art: art/runtime/java_vm_ext.cc:410] at org.appcelerator.titanium.TiLaunchActivity.loadActivityScript(TiLaunchActivity.java:128) [INFO] : art: art/runtime/java_vm_ext.cc:410] at org.appcelerator.titanium.TiLaunchActivity.windowCreated(TiLaunchActivity.java:183) [INFO] : art: art/runtime/java_vm_ext.cc:410] at org.appcelerator.titanium.TiRootActivity.windowCreated(TiRootActivity.java:107) [INFO] : art: art/runtime/java_vm_ext.cc:410] at org.appcelerator.titanium.TiBaseActivity.onCreate(TiBaseActivity.java:675) [INFO] : art: art/runtime/java_vm_ext.cc:410] at org.appcelerator.titanium.TiLaunchActivity.onCreate(TiLaunchActivity.java:169) [INFO] : art: art/runtime/java_vm_ext.cc:410] at org.appcelerator.titanium.TiRootActivity.onCreate(TiRootActivity.java:96) [INFO] : art: art/runtime/java_vm_ext.cc:410] at android.app.Activity.performCreate(Activity.java:6251) [INFO] : art: art/runtime/java_vm_ext.cc:410] at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) [INFO] : art: art/runtime/java_vm_ext.cc:410] at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) [INFO] : art: art/runtime/java_vm_ext.cc:410] at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) [INFO] : art: art/runtime/java_vm_ext.cc:410] at android.app.ActivityThread.-wrap11(ActivityThread.java:-1) [INFO] : art: art/runtime/java_vm_ext.cc:410] at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) [INFO] : art: art/runtime/java_vm_ext.cc:410] at android.os.Handler.dispatchMessage(Handler.java:102) [INFO] : art: art/runtime/java_vm_ext.cc:410] at android.os.Looper.loop(Looper.java:148) [INFO] : art: art/runtime/java_vm_ext.cc:410] at android.app.ActivityThread.main(ActivityThread.java:5422) [INFO] : art: art/runtime/java_vm_ext.cc:410] at java.lang.reflect.Method.invoke!(Native method) [INFO] : art: art/runtime/java_vm_ext.cc:410] at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) [INFO] : art: art/runtime/java_vm_ext.cc:410] at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) [INFO] : art: art/runtime/java_vm_ext.cc:410] [INFO] : art: art/runtime/runtime.cc:366] Runtime aborting... [INFO] : art: art/runtime/runtime.cc:366] Aborting thread: [INFO] : art: art/runtime/runtime.cc:366] "main" prio=5 tid=1 Native [INFO] : art: art/runtime/runtime.cc:366] | group="" sCount=0 dsCount=0 obj=0x73b922a0 self=0xf4e76500 [INFO] : art: art/runtime/runtime.cc:366] | sysTid=10996 nice=0 cgrp=default sched=0/0 handle=0xf7028b34 [INFO] : art: art/runtime/runtime.cc:366] | state=R schedstat=( 549853712 16660679 138 ) utm=41 stm=12 core=4 HZ=100 [INFO] : art: art/runtime/runtime.cc:366] | stack=0xff616000-0xff618000 stackSize=8MB [INFO] : art: art/runtime/runtime.cc:366] | held mutexes= "abort lock" [INFO] : art: art/runtime/runtime.cc:366] native: #00 pc 0035a55f /system/lib/libart.so (_ZN3art15DumpNativeStackERNSt3__113basic_ostreamIcNS0_11char_traitsIcEEEEiPKcPNS_9ArtMethodEPv+126) [INFO] : art: art/runtime/runtime.cc:366] native: #01 pc 0033b0e7 /system/lib/libart.so (_ZNK3art6Thread4DumpERNSt3__113basic_ostreamIcNS1_11char_traitsIcEEEE+138) [INFO] : art: art/runtime/runtime.cc:366] native: #02 pc 0031f455 /system/lib/libart.so (_ZNK3art10AbortState10DumpThreadERNSt3__113basic_ostreamIcNS1_11char_traitsIcEEEEPNS_6ThreadE+20) [INFO] : art: art/runtime/runtime.cc:366] native: #03 pc 0031f6d1 /system/lib/libart.so (_ZN3art7Runtime5AbortEv+540) [INFO] : art: art/runtime/runtime.cc:366] native: #04 pc 000f3969 /system/lib/libart.so (_ZN3art10LogMessageD2Ev+2092) [INFO] : art: art/runtime/runtime.cc:366] native: #05 pc 0024e2d5 /system/lib/libart.so (_ZN3art9JavaVMExt8JniAbortEPKcS2_+1528) [INFO] : art: art/runtime/runtime.cc:366] native: #06 pc 0024e6d3 /system/lib/libart.so (_ZN3art9JavaVMExt9JniAbortFEPKcS2_z+62) [INFO] : art: art/runtime/runtime.cc:366] native: #07 pc 0027d48f /system/lib/libart.so (_ZN3art3JNI17CallObjectMethodVEP7_JNIEnvP8_jobjectP10_jmethodIDSt9__va_list+458) [INFO] : art: art/runtime/runtime.cc:366] native: #08 pc 002c2839 /data/app/com.appc.intents-1/lib/arm/libkroll-v8.so (_ZN7_JNIEnv16CallObjectMethodEP8_jobjectP10_jmethodIDz+28) [INFO] : art: art/runtime/runtime.cc:366] native: #09 pc 002c4c57 /data/app/com.appc.intent {noformat}

Expected

No error is thrown.

Comments

  1. Christopher Williams 2016-10-10

    The root cause here is the KrollBindings.getExternalCommonJsModule() call. It's saying the methodID used to call a native Java method (specifically to load source code) is null. If I were to guess it's probably because we have some mismatch on the internal map we store between module ids and the KrollSourceProvider instance/method used to retrieve the source.
  2. Christopher Williams 2016-10-10

    May be related to iOS issue, we may only be crashing when requiring a path _under_ a native module?
  3. Christopher Williams 2016-10-10

    I combined this fix with the similar fix on iOS. Should likely cherry-pick the two commits to 6_0_X if the PR is approved/merged. Android 6.1.0/master PR: https://github.com/appcelerator/titanium_mobile/pull/8493
  4. Lokesh Choudhary 2016-10-12

    [~cwilliams], If I run
       var Intent = require('android.content.Intent');
       var intent = Ti.Android.createIntent();
       var nativeIntent = new Intent(intent);
       
    with the fix in master 6.1.0.v20161012092744 I get the following error:
       [ERROR] :  TiExceptionHandler: (main) [138,138] ----- Titanium Javascript Runtime Error -----
       [ERROR] :  TiExceptionHandler: (main) [1,139] - In ti:/module.js:301,2
       [ERROR] :  TiExceptionHandler: (main) [0,139] - Message: Uncaught Error: Requested module not found: android.content
       [ERROR] :  TiExceptionHandler: (main) [0,139] - Source: 	throw new Error("Requested module not found: " + request); // TODO Set 'code' property to 'MODULE_NOT_FOUND' to match Node?
       
    Environment: Appc Studio : 4.8.0.201610060953 Ti SDK : 6.1.0.v20161012092744 Ti CLI : 5.0.10 Alloy : 1.9.2 MAC El Capitan : 10.11.6 Appc NPM : 4.2.8-7 Appc CLI : 6.0.0-57 Node: 4.6.0 Hyperloop: 2.0.0 on preprod
  5. Christopher Williams 2016-10-12

    [~lchoudhary] Are you testing with hyperloop 2.0.0 as well? That sample code is actually hyperloop code. If you just want to test the fix in the SDK without hyperloop, we need to set up something like what I added to the unit tests. Basically you want to try and require a path whose first segment matches a native module id used by the project, but that doesn't actually live in that module. You could try just doing:
       var dont_crash = require('facebook/madeup');
       
    In a project that has the Facebook module in the tiapp.xml modules listing for android. That used to crash the app. Now I assume it'll throw an error about being unable to require the file. If you wanted to go further and do what the unit test does already, you can then add a 'facebook' folder in the app's Resources folder. Then inside that, add a 'madeup.js' file with these contents:
       module.exports = {
         name: 'madeup.js'
       };
       
    Then this in your app.js should work:
       var dont_crash = require('facebook/madeup');
       Ti.API.info(dont_crash.name);
       
  6. Christopher Williams 2016-10-12

    ah crap, I'm getting the same thing. Looking at it now...
  7. Christopher Williams 2016-10-12

    So there's actually other issues that are causing what you see [~lchoudhary]. I'm going to open proper tickets for those, as they're actually in the hyperloop module itself. For now, you should be able to confirm this particular Android SDK fix with the steps I outlined above.
  8. Eric Merriman 2018-08-06

    Cleaning up older fixed issues. If this issue should not have been closed as fixed, please reopen.

JSON Source