UP-3704 : Added null check to a loop when collecting grouping