Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26843] Android: Getting/Setting TabGroup "activeTab" property before open causes a crash as of 8.0.0.RC

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2019-03-08T18:34:23.000+0000
Affected Version/sRelease 8.0.0
Fix Version/sRelease 8.0.0
ComponentsAndroid
LabelsTabGroup, android, regression
ReporterJosh Longton
AssigneeYordan Banev
Created2019-02-21T16:04:25.000+0000
Updated2019-03-08T18:34:23.000+0000

Description

*Summary:* Getting or setting the TabGroup "activeTab" property (or calling getActiveTab() or setActiveTab() methods) before the TabGroup has been opened causes a crash on Android as of Titanium 8.0.0.RC. *Steps to reproduce*

Build and run the below code via Titanium 8.0.0.RC on Android.

Notice the app crashes on startup.

*Testcase* {noformat} var tabGroup = Ti.UI.createTabGroup(); var win1 = Titanium.UI.createWindow({ title: 'Tab 1', backgroundColor: '#fff' }); var tab1 = Titanium.UI.createTab({ title: 'Tab 1', window: win1 }); var label1 = Titanium.UI.createLabel({ color: '#999', text: 'I am Window 1', textAlign: 'center', width: 'auto' }); win1.add(label1); var win2 = Titanium.UI.createWindow({ title: 'Tab 2', backgroundColor: '#fff' }); var tab2 = Titanium.UI.createTab({ title: 'Tab 2', window: win2 }); var label2 = Titanium.UI.createLabel({ color: '#999', text: 'I am Window 2', textAlign: 'center', width: 'auto' }); win2.add(label2); tabGroup.addTab(tab1); tabGroup.addTab(tab2); tabGroup.activeTab = 1; Ti.API.info("### activeTab: " + tabGroup.activeTab); tabGroup.open(); {noformat} *Expected* No error is thrown and the seconf tab is in focus *Actual* {noformat} [ERROR] TiExceptionHandler: (main) [70,70] Attempt to invoke virtual method 'void ti.modules.titanium.ui.widget.tabgroup.TiUITab.onSelectionChange(boolean)' on a null object reference [ERROR] TiExceptionHandler: [ERROR] TiExceptionHandler: ti.modules.titanium.ui.TabProxy.onSelectionChanged(TabProxy.java:220) [ERROR] TiExceptionHandler: ti.modules.titanium.ui.TabGroupProxy.onTabSelected(TabGroupProxy.java:551) [ERROR] TiExceptionHandler: ti.modules.titanium.ui.TabGroupProxy.onTabSelected(TabGroupProxy.java:521) [ERROR] TiExceptionHandler: ti.modules.titanium.ui.widget.tabgroup.TiUITabLayoutTabGroup.onTabSelected(TiUITabLayoutTabGroup.java:232) [ERROR] TiExceptionHandler: android.support.design.widget.TabLayout.dispatchTabSelected(TabLayout.java:1165) [ERROR] TiExceptionHandler: android.support.design.widget.TabLayout.selectTab(TabLayout.java:1158) [ERROR] TiExceptionHandler: android.support.design.widget.TabLayout.selectTab(TabLayout.java:1128) [ERROR] TiExceptionHandler: android.support.design.widget.TabLayout$Tab.select(TabLayout.java:1427) [ERROR] TiExceptionHandler: android.support.design.widget.TabLayout.addTab(TabLayout.java:483) [ERROR] TiExceptionHandler: android.support.design.widget.TabLayout.addTab(TabLayout.java:465) [ERROR] TiExceptionHandler: android.support.design.widget.TabLayout.addTab(TabLayout.java:444) [ERROR] TiExceptionHandler: ti.modules.titanium.ui.widget.tabgroup.TiUITabLayoutTabGroup.addTabItemInController(TiUITabLayoutTabGroup.java:159) [ERROR] TiExceptionHandler: ti.modules.titanium.ui.widget.tabgroup.TiUIAbstractTabGroup.addTab(TiUIAbstractTabGroup.java:199) [ERROR] TiExceptionHandler: ti.modules.titanium.ui.TabGroupProxy.handlePostOpen(TabGroupProxy.java:442) [ERROR] TiExceptionHandler: ti.modules.titanium.ui.TabGroupProxy.windowCreated(TabGroupProxy.java:416) [ERROR] TiExceptionHandler: org.appcelerator.titanium.TiActivityWindows.windowCreated(TiActivityWindows.java:33) [ERROR] TiExceptionHandler: org.appcelerator.titanium.TiBaseActivity.windowCreated(TiBaseActivity.java:624) [ERROR] TiExceptionHandler: org.appcelerator.titanium.TiBaseActivity.onCreate(TiBaseActivity.java:767) [ERROR] TiExceptionHandler: org.appcelerator.titanium.TiActivity.onCreate(TiActivity.java:21) [ERROR] TiExceptionHandler: android.app.Activity.performCreate(Activity.java:6975) [ERROR] TiExceptionHandler: android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213) [ERROR] TiExceptionHandler: android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770) [ERROR] TiExceptionHandler: android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) [ERROR] TiExceptionHandler: android.app.ActivityThread.-wrap11(Unknown Source:0) [ERROR] TiExceptionHandler: android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) [ERROR] TiExceptionHandler: android.os.Handler.dispatchMessage(Handler.java:105) [ERROR] TiExceptionHandler: android.os.Looper.loop(Looper.java:164) [ERROR] TiExceptionHandler: android.app.ActivityThread.main(ActivityThread.java:6541) [ERROR] TiExceptionHandler: java.lang.reflect.Method.invoke(Native Method) [ERROR] TiExceptionHandler: com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) [ERROR] TiExceptionHandler: com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) {noformat} *Note:* It will crash when set via a Ti.UI.createTabGroup() creation property as well. *Work-Around:* You can set the active tab after the TabGroup has been opened as shown below.
tabGroup.addEventListener("open", function() {
	tabGroup.activeTab = 1;
});

Comments

  1. Joshua Quick 2019-02-21

    We only have 1 unit test for setting "activeTab" and it is done after the TabGroup has been opened. https://github.com/appcelerator/titanium-mobile-mocha-suite/blob/master/Resources/ti.ui.tabgroup.test.js We should add 2 more unit tests for: * Setting "activeTab" to an integer via a Ti.UI.createTabGroup() creation property. * Setting "activeTab" to an integer after the Ti.UI.createTabGroup() function call, but before open. For both tests above, we should read the TabGroup.activeTab property immediately afterwards and verify that it is assigned to the correct value. This is to verify that the getter does not crash on Android either. I've tested doing the above on iOS (assigning them to an int before open) and it works fine. This is just a regression on Android in 8.0.0.RC.
  2. Joshua Quick 2019-02-22

    We also have an API doc issue. We document that the TabGroup.setActiveTab() method (which is deprecated as of 8.0.0) supports types Number and Ti.UI.Tab, which is true. Our TabGroup.activeTab property documents that it only supports Ti.UI.Tab. The property's documentation needs to be updated to indicate it supports Number as well, just like the setter method. https://github.com/appcelerator/titanium_mobile/blob/master/apidoc/Titanium/UI/TabGroup.yml#L269
  3. Yordan Banev 2019-03-01

    PR: https://github.com/appcelerator/titanium_mobile/pull/10740
  4. Keerthi Mahalingam 2019-03-04

    FR passed. Waiting for resolving Test failure in jenkins and back port PR for 8.0
  5. Yordan Banev 2019-03-07

    PR (8_0_X): https://github.com/appcelerator/titanium_mobile/pull/10759
  6. Keerthi Mahalingam 2019-03-07

    FR passed . Jenkins is failing. Waiting for Resolving jenkin test failure to merge.
  7. Christopher Williams 2019-03-08

    keerthi did the FR while this was still a PR on Github. I've merged the master and 8_0_X PRs.

JSON Source