Program: 78794
Project: 78794
Buggy source:
/** 
 * The second step to work with the cascading parameters. Get the selection choices for a parameter in the cascading group. The parameter to work on is the parameter on the next level in the parameter cascading hierarchy. For the "parameter to work on", please see the following example. Assume we have a cascading parameter group as Country - State - City. If user specified an empty array in groupKeyValues (meaning user doesn't have any parameter value), the parameter to work on will be the first level which is Country in this case. If user specified groupKeyValues as Object[]{"USA"} (meaning user has set the value of the top level), the parameter to work on will be the second level which is State in "USA" in this case. If user specified groupKeyValues as Object[]{"USA", "CA"} (meaning user has set the values of the top and the second level), the parameter to work on will be the third level which is City in "USA, CA" in this case.
 * @param parameterGroupName -the cascading parameter group name
 * @param groupKeyValues -the array of known parameter values (see the example above)
 * @return the selection list of the parameter to work on
 */
public Collection getSelectionListForCascadingGroup(String parameterGroupName,Object[] groupKeyValues){
  CascadingParameterGroupHandle parameterGroup=getCascadingParameterGroup(parameterGroupName);
  if (parameterGroup == null)   return null;
  IResultIterator iter=(IResultIterator)dataCache.get(parameterGroup.getName());
  if (iter == null)   return null;
  SlotHandle slotHandle=parameterGroup.getParameters();
  assert(groupKeyValues.length < slotHandle.getCount());
  int skipLevel=groupKeyValues.length + 1;
  ScalarParameterHandle requestedParam=(ScalarParameterHandle)slotHandle.get(groupKeyValues.length);
  int listLimit=requestedParam.getListlimit();
  boolean fixedOrder=requestedParam.isFixedOrder();
  ScriptExpression labelExpr=(ScriptExpression)labelMap.get(parameterGroup.getName() + "String_Node_Str" + requestedParam.getName());
  ScriptExpression valueExpr=(ScriptExpression)valueMap.get(parameterGroup.getName() + "String_Node_Str" + requestedParam.getName());
  ArrayList choices=new ArrayList();
  try {
    if (skipLevel > 1)     iter.findGroup(groupKeyValues);
    int startGroupLevel=skipLevel - 1;
    int count=0;
    while (iter.next()) {
      String label=(labelExpr != null ? iter.getString(labelExpr) : null);
      Object value=iter.getValue(valueExpr);
      choices.add(new SelectionChoice(label,value));
      count++;
      if ((listLimit != 0) && (count >= listLimit))       break;
      iter.skipToEnd(skipLevel);
      int endGroupLevel=iter.getEndingGroupLevel();
      if (endGroupLevel <= startGroupLevel) {
        break;
      }
    }
  }
 catch (  BirtException e) {
    e.printStackTrace();
  }
  if (!fixedOrder)   Collections.sort(choices,new SelectionChoiceComparator(true));
  return choices;
}

Fixed version (ground truth):
/** 
 * The second step to work with the cascading parameters. Get the selection choices for a parameter in the cascading group. The parameter to work on is the parameter on the next level in the parameter cascading hierarchy. For the "parameter to work on", please see the following example. Assume we have a cascading parameter group as Country - State - City. If user specified an empty array in groupKeyValues (meaning user doesn't have any parameter value), the parameter to work on will be the first level which is Country in this case. If user specified groupKeyValues as Object[]{"USA"} (meaning user has set the value of the top level), the parameter to work on will be the second level which is State in "USA" in this case. If user specified groupKeyValues as Object[]{"USA", "CA"} (meaning user has set the values of the top and the second level), the parameter to work on will be the third level which is City in "USA, CA" in this case.
 * @param parameterGroupName -the cascading parameter group name
 * @param groupKeyValues -the array of known parameter values (see the example above)
 * @return the selection list of the parameter to work on
 */
public Collection getSelectionListForCascadingGroup(String parameterGroupName,Object[] groupKeyValues){
  CascadingParameterGroupHandle parameterGroup=getCascadingParameterGroup(parameterGroupName);
  if (parameterGroup == null)   return Collections.EMPTY_LIST;
  IResultIterator iter=(IResultIterator)dataCache.get(parameterGroup.getName());
  if (iter == null)   return Collections.EMPTY_LIST;
  SlotHandle slotHandle=parameterGroup.getParameters();
  assert(groupKeyValues.length < slotHandle.getCount());
  int skipLevel=groupKeyValues.length + 1;
  ScalarParameterHandle requestedParam=(ScalarParameterHandle)slotHandle.get(groupKeyValues.length);
  int listLimit=requestedParam.getListlimit();
  boolean fixedOrder=requestedParam.isFixedOrder();
  ScriptExpression labelExpr=(ScriptExpression)labelMap.get(parameterGroup.getName() + "String_Node_Str" + requestedParam.getName());
  ScriptExpression valueExpr=(ScriptExpression)valueMap.get(parameterGroup.getName() + "String_Node_Str" + requestedParam.getName());
  ArrayList choices=new ArrayList();
  try {
    if (skipLevel > 1)     iter.findGroup(groupKeyValues);
    int startGroupLevel=skipLevel - 1;
    int count=0;
    while (iter.next()) {
      String label=(labelExpr != null ? iter.getString(labelExpr) : null);
      Object value=iter.getValue(valueExpr);
      choices.add(new SelectionChoice(label,value));
      count++;
      if ((listLimit != 0) && (count >= listLimit))       break;
      iter.skipToEnd(skipLevel);
      int endGroupLevel=iter.getEndingGroupLevel();
      if (endGroupLevel <= startGroupLevel) {
        break;
      }
    }
  }
 catch (  BirtException e) {
    e.printStackTrace();
  }
  if (!fixedOrder)   Collections.sort(choices,new SelectionChoiceComparator(true));
  return choices;
}