fix npe, write url if invalid