[core] Fix potential null pointer in TwoWayLayoutManager
[layouts] Fix potential null pointer in BaseLayoutManager