Prevent NPE removing unnecessary code

Change-Id: Iffe437542f9a7f36085cb9a6c9433f3c76f10581