Fixed a bug that API throws a NPE.