Project: titanium
Issue TIMOB-15872: Android: NPE at android.view.ViewConfiguration.get()
h4. Problem Google Play Crash reports contain multiple of the following NullPointerExceptions occuring at the same place: {code} java.lang.NullPointerException at android.view.ViewConfiguration.get(ViewConfiguration.java:228) at android.view.View.(View.java:1888) at android.view.ViewGroup.(ViewGroup.java:281) at android.widget.FrameLayout.(FrameLayout.java:80) at ti.modules.titanium.ui.widget.tableview.TiTableView.(TiTableView.java:266) at ti.modules.titanium.ui.widget.TiUITableView.processProperties(TiUITableView.java:106) at org.appcelerator.kroll.KrollProxy.setModelListener(KrollProxy.java:1129) at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:469) at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:460) at org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:438) at ti.modules.titanium.ui.TableViewProxy.getTableView(TableViewProxy.java:146) at ti.modules.titanium.ui.TableViewProxy.handleSetData(TableViewProxy.java:689) at ti.modules.titanium.ui.TableViewProxy.handleMessage(TableViewProxy.java:866) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:130) at android.app.ActivityThread.main(ActivityThread.java:3691) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665) at dalvik.system.NativeStart.main(Native Method) {code} {code} Caused by: java.lang.NullPointerException at android.view.ViewConfiguration.get(ViewConfiguration.java:230) at android.view.View.(View.java:1920) at android.view.ViewGroup.(ViewGroup.java:303) at android.widget.FrameLayout.(FrameLayout.java:80) at ti.modules.titanium.ui.widget.tableview.TiTableView.(TiTableView.java:266) at ti.modules.titanium.ui.widget.TiUITableView.processProperties(TiUITableView.java:106) at org.appcelerator.kroll.KrollProxy.setModelListener(KrollProxy.java:1129) at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:469) at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:460) at org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:438) at ti.modules.titanium.ui.TableViewProxy.getTableView(TableViewProxy.java:146) at ti.modules.titanium.ui.TableViewProxy.handleSetData(TableViewProxy.java:689) at ti.modules.titanium.ui.TableViewProxy.handleMessage(TableViewProxy.java:866) at android.os.Handler.dispatchMessage(Handler.java:95) at org.appcelerator.kroll.common.TiMessenger.dispatchMessage(TiMessenger.java:364) at org.appcelerator.kroll.common.TiMessenger.dispatchPendingMessages(TiMessenger.java:349) at org.appcelerator.kroll.common.TiMessenger$2.getResult(TiMessenger.java:234) at org.appcelerator.kroll.common.TiMessenger.sendBlockingMessage(TiMessenger.java:261) at org.appcelerator.kroll.common.TiMessenger.sendBlockingRuntimeMessage(TiMessenger.java:186) at org.appcelerator.kroll.KrollProxy.fireSyncEvent(KrollProxy.java:740) at org.appcelerator.titanium.TiBaseActivity.onStop(TiBaseActivity.java:1058) at org.appcelerator.titanium.TiLaunchActivity.onStop(TiLaunchActivity.java:355) at android.app.Instrumentation.callActivityOnStop(Instrumentation.java:1272) at android.app.Activity.performStop(Activity.java:4073) at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3127) ... 11 more {code} {code} Caused by: java.lang.NullPointerException at android.view.ViewConfiguration.get(ViewConfiguration.java:228) at android.view.View.(View.java:1878) at android.view.ViewGroup.(ViewGroup.java:281) at android.widget.FrameLayout.(FrameLayout.java:80) at ti.modules.titanium.ui.widget.tableview.TiTableView.(TiTableView.java:266) at ti.modules.titanium.ui.widget.TiUITableView.processProperties(TiUITableView.java:106) at org.appcelerator.kroll.KrollProxy.setModelListener(KrollProxy.java:1129) at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:469) at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:460) at org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:438) at ti.modules.titanium.ui.TableViewProxy.getTableView(TableViewProxy.java:146) at ti.modules.titanium.ui.TableViewProxy.handleSetData(TableViewProxy.java:689) at ti.modules.titanium.ui.TableViewProxy.handleMessage(TableViewProxy.java:866) at android.os.Handler.dispatchMessage(Handler.java:95) at org.appcelerator.kroll.common.TiMessenger.dispatchMessage(TiMessenger.java:364) at org.appcelerator.kroll.common.TiMessenger.dispatchPendingMessages(TiMessenger.java:349) at org.appcelerator.kroll.common.TiMessenger$2.getResult(TiMessenger.java:234) at org.appcelerator.kroll.common.TiMessenger.sendBlockingMessage(TiMessenger.java:261) at org.appcelerator.kroll.common.TiMessenger.sendBlockingRuntimeMessage(TiMessenger.java:186) at org.appcelerator.kroll.KrollProxy.fireSyncEvent(KrollProxy.java:740) at org.appcelerator.titanium.TiBaseActivity.onPause(TiBaseActivity.java:917) at org.appcelerator.titanium.TiLaunchActivity.onPause(TiLaunchActivity.java:339) at android.app.Activity.performPause(Activity.java:3851) at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1191) at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2345) ... 12 more {code} h4. Test Case Unfortunately, I haven't been able to find steps to reproduce this issue. The best way to go forward in my opinion is to analyze the code and to try and figure out from there, what is going wrong. h4. My Analysis From the code I see, that in the TiTableViewConstructor a call to "super(proxy.getActivity())" is done. In "proxy.getActivity()" it is noted, that this may return "null". I assume that this would lead to the crash reports above. Could it be that we have a possible race condition or something similar here, where "proxy.getActivity()" is called, before the proxy actually has an activity assigned to it? Is anyone else seeing this problem on a large installation base? It would be great to improve the stability of Titanium further by fixing this issue.
Story points: 3