timob-12857: fix edge case crashes

Test case in JIRA: https://jira.appcelerator.org/browse/TIMOB-12857