[layouts] Fix potential null pointer in BaseLayoutManager