[TIMOB-26843] Android: Getting/Setting TabGroup "activeTab" property before open causes a crash as of 8.0.0.RC
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2019-03-08T18:34:23.000+0000 |
Affected Version/s | Release 8.0.0 |
Fix Version/s | Release 8.0.0 |
Components | Android |
Labels | TabGroup, android, regression |
Reporter | Josh Longton |
Assignee | Yordan Banev |
Created | 2019-02-21T16:04:25.000+0000 |
Updated | 2019-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 aTi.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;
});
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 aTi.UI.createTabGroup()
creation property. * Setting "activeTab" to an integer after theTi.UI.createTabGroup()
function call, but before open. For both tests above, we should read theTabGroup.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.We also have an API doc issue. We document that the
TabGroup.setActiveTab()
method (which is deprecated as of 8.0.0) supports typesNumber
andTi.UI.Tab
, which is true. OurTabGroup.activeTab
property documents that it only supportsTi.UI.Tab
. The property's documentation needs to be updated to indicate it supportsNumber
as well, just like the setter method. https://github.com/appcelerator/titanium_mobile/blob/master/apidoc/Titanium/UI/TabGroup.yml#L269PR: https://github.com/appcelerator/titanium_mobile/pull/10740
FR passed. Waiting for resolving Test failure in jenkins and back port PR for 8.0
PR (8_0_X): https://github.com/appcelerator/titanium_mobile/pull/10759
FR passed . Jenkins is failing. Waiting for Resolving jenkin test failure to merge.
keerthi did the FR while this was still a PR on Github. I've merged the master and 8_0_X PRs.