Java NPE resolved (testing if object is null)