[TIMOB-13560](3_1_X) Add nil check

Cherry Pick PR #4242 into 3_1_X

Test is in [JIRA](https://jira.appcelerator.org/browse/TIMOB-13560)

Run KS for sanity please