fix a NPE issue which might happen in some special cases