Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25456] Android: Crash after calling Stringify on Ti.UI.Window

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2017-11-13T22:45:28.000+0000
Affected Version/sRelease 6.2.0
Fix Version/sRelease 7.0.0
ComponentsAndroid
Labelsandroid
ReporterYordan Banev
AssigneeYordan Banev
Created2017-10-30T11:49:45.000+0000
Updated2017-11-23T17:26:46.000+0000

Description

Calling Stringify on a Window instance before it has been opened crashes the application. *Test case:*
var win = Ti.UI.createWindow();
Ti.API.error(JSON.stringify(win));
win.open();
_Result_: Application crashes. _Expected behavior_: Application should not crash. *Console log:*
[WARN] :   W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method ‘void android.support.v7.app.ActionBar.setDisplayOptions(int)’ on a null object reference
[WARN] :   W/System.err:     at org.appcelerator.titanium.proxy.ActionBarProxy.<init>(ActionBarProxy.java:58)
[WARN] :   W/System.err:     at org.appcelerator.titanium.proxy.ActivityProxy.getActionBar(ActivityProxy.java:258)
[WARN] :   W/System.err:     at org.appcelerator.kroll.runtime.v8.V8Runtime.nativeRunModule(Native Method)
[WARN] :   W/System.err:     at org.appcelerator.kroll.runtime.v8.V8Runtime.doRunModule(V8Runtime.java:196)
[WARN] :   W/System.err:     at org.appcelerator.kroll.KrollRuntime.runModule(KrollRuntime.java:243)
[WARN] :   W/System.err:     at org.appcelerator.titanium.TiLaunchActivity.loadActivityScript(TiLaunchActivity.java:128)
[WARN] :   W/System.err:     at org.appcelerator.titanium.TiLaunchActivity.windowCreated(TiLaunchActivity.java:183)
[WARN] :   W/System.err:     at org.appcelerator.titanium.TiRootActivity.windowCreated(TiRootActivity.java:172)
[WARN] :   W/System.err:     at org.appcelerator.titanium.TiBaseActivity.onCreate(TiBaseActivity.java:684)
[WARN] :   W/System.err:     at org.appcelerator.titanium.TiLaunchActivity.onCreate(TiLaunchActivity.java:169)
[WARN] :   W/System.err:     at org.appcelerator.titanium.TiRootActivity.onCreate(TiRootActivity.java:161)
[WARN] :   W/System.err:     at android.app.Activity.performCreate(Activity.java:6679)
[WARN] :   W/System.err:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
[WARN] :   W/System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
[WARN] :   W/System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
[WARN] :   W/System.err:     at android.app.ActivityThread.-wrap12(ActivityThread.java)
[WARN] :   W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
[WARN] :   W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
[WARN] :   W/System.err:     at android.os.Looper.loop(Looper.java:154)
[WARN] :   W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:6119)
[WARN] :   W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
[WARN] :   W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
[WARN] :   W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

Comments

  1. Caio Perdona 2017-11-07

    Getting the same error here, with SDK 6.3.0.GA. Is there any workaround for this? My log is below: {noformat} [ERROR] TiExceptionHandler: (main) [0,333] - Message: Uncaught Attempt to invoke virtual method ‘void android.support.v7.app.ActionBar.setDisplayOptions(int)’ on a null object reference {noformat}
  2. Caio Perdona 2017-11-08

    I have a constructor for my windows, so that I can customize programmatically some window properties. Below is the code I'm using, it may help you identify the bug... PS: I tried to play with some timeouts (because Ti seems to lose reference of activity/actionBar) but did not have any luck.
       exports.window = function(args) {
       
           args["backgroundColor"] = args["backgroundColor"] || "#fff";
           args["orientationModes"] = args["orientationModes"] || [Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT, Ti.UI.PORTRAIT];
       
           var logo = ui.image({
               image: "/img/general/logo-pinion.png",
               width: 100,
               height: 24
           });
       
           if (osname == "iphone") {
               args["titleAttributes"] = {color: "#fff"};
               args["titleControl"] = (args["title"]) ? null : logo;
               args["navTintColor"] = "#fff";
               args["tintColor"] = args["tintColor"] || "#328cff";
               args["barColor"] = args["barColor"] || "#025ed1";
               args["backButtonTitle"] = args["backButtonTitle"] || L("navBackBt");
               args["statusBarStyle"] = Ti.UI.iOS.StatusBar.LIGHT_CONTENT;
           } else {
               args["windowSoftInputMode"] = Ti.UI.Android.SOFT_INPUT_STATE_HIDDEN | Ti.UI.Android.SOFT_INPUT_ADJUST_PAN;
               args["theme"] = args["theme"] || "Theme.AppCompat.Light.DarkActionBar";
           }
       
           var w = Ti.UI.createWindow(args);
       
           if (args["hasLoading"]) {
               ui.loading(w, args["slay"] || false);
           }
       
           if (osname == "android" && !args["tabgroupWin"]) {
       
               w.addEventListener("open", function(e) {
                   w.addEventListener("open", function(e) {
                   // CHANGE ACTIONBAR COLOR
                   abx.window = w;
                   abx.setBackgroundColor("#025ed1");
       
                   var activity = w.getActivity();
                   var actionBar = activity.getActionBar();
       
                   if (actionBar) {
                       if (args["canGoBack"]) {
                           actionBar.setDisplayHomeAsUp(true);
                           actionBar.onHomeIconItemSelected = function() {
                               w.close();
                           };
                       }
                   }
       
                   if (args["report"] || args["settings"]) {
       
                       activity.onCreateOptionsMenu = function(e) {
       
                           var menu = e.menu;
                           menu.clear();
       
                           if (args["report"]) {
                               ui.createNavIcon("report", args["report"], "android", menu);
                           }
       
                           if (args["settings"]) {
                               ui.createNavIcon("settings", null, "android", menu);
                           }
       
                       };
       
                   }
       
               });
       
               w.fbProxy = fb.createActivityWorker({lifecycleContainer: w});
       
           } else if (osname == "iphone") {
       
               if (args["settings"]) {
                   w.setLeftNavButton(ui.createNavIcon("settings"));
               }
       
               if (args["report"]) {
                   w.setRightNavButton(ui.createNavIcon("report", args["report"]));
               }
       
               if (args["mapview"]) {
                   w.setRightNavButton(ui.createNavIcon("mapview"));
               }
       
               if (args["redeem"]) {
                   w.setLeftNavButton(ui.createNavIcon("redeem"));
               }
       
           }
       
           return w;
       };
       
  3. Abir Mukherjee 2017-11-13

    FR passed; PR merged.
  4. Caio Perdona 2017-11-14

    Thats great news! =] Can you provide us more information to workaround in current SDK version? Thanks!
  5. Abir Mukherjee 2017-11-15

    Changes are seen in SDK 7.0.0.v20171114202841.
  6. Caio Perdona 2017-11-21

    What about current projects that need to be released on CURRENT 6.3.0.GA SDK?
  7. Hans Knöchel 2017-11-21

    [~perdona] Please feel free to patch the following [5 lines](https://github.com/appcelerator/titanium_mobile/pull/9570/files#diff-795f7c4f31e823f6efcb79974c240224R58-R63) using the linked change. You just check-out the 6_3_X branch, which is the stable GA, apply the patch, compile it in build/ by using node scons.js cleanbuild and use the resulting SDK (will be 6.3.1). Hope that helps! Otherwise we'll grab a build for you ;-).
  8. Caio Perdona 2017-11-22

    Hans, thanks for the feedback. I'm trying to build the module here, but I'm getting the following {noformat} BUILD SUCCESSFUL Total time: 3 seconds path.js:7 throw new TypeError('Path must be a string. Received ' + inspect(path)); ^ TypeError: Path must be a string. Received null at assertPath (path.js:7:11) at Object.join (path.js:1213:7) at AndroidSDK.getPlatformDir (/Users/perdona/Dev/lab/TI/titanium_mobile/build/androidsdk.js:64:24) at Android.build (/Users/perdona/Dev/lab/TI/titanium_mobile/build/android.js:52:28) at /Users/perdona/Dev/lab/TI/titanium_mobile/build/scons-cleanbuild.js:95:26 at /Users/perdona/Dev/lab/TI/titanium_mobile/node_modules/async/dist/async.js:3047:16 at replenish (/Users/perdona/Dev/lab/TI/titanium_mobile/node_modules/async/dist/async.js:982:17) at /Users/perdona/Dev/lab/TI/titanium_mobile/node_modules/async/dist/async.js:986:9 at eachLimit$1 (/Users/perdona/Dev/lab/TI/titanium_mobile/node_modules/async/dist/async.js:3133:22) at Object. (/Users/perdona/Dev/lab/TI/titanium_mobile/node_modules/async/dist/async.js:1016:16) {noformat} (Maybe my node environment is broken?) Can you provide or a workaround for this error in my build?
  9. Hans Knöchel 2017-11-23

    Looks like your Android SDK / NDK path is not set correctly. Change with appc ti setup android. For example, my android-sdk is in /opt/android-sdk and the android-ndk in /opt/android-ndk.
  10. Hans Knöchel 2017-11-23

    I generated a custom 6_3_X SDK (6.3.1) with this ticket being added, feel free to test it [~perdona]! Please note that we cannot do that all the time, so try to fix the build-setup as well to be more flexible for the future :-) Download: https://www.dropbox.com/s/zelfowjcypj4a1h/mobilesdk-6.3.1-perdona.zip?dl=1
  11. Caio Perdona 2017-11-23

    Just tested and it seems to work fine without any errors... Huge thanks to Hans for providing support on this issue!

JSON Source