Program: 79049
Project: 79049
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 getSelectionChoicesForCascadingGroup(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();
  String valueType=requestedParam.getDataType();
  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 count=0;
    while (iter.next()) {
      String label=iter.getString(labelExpr);
      Object value=iter.getValue(valueExpr);
      value=convertToType(value,valueType);
      choices.add(new SelectionChoice(label,value));
      count++;
      if ((listLimit != 0) && (count >= listLimit))       break;
      iter.skipToEnd(skipLevel);
    }
  }
 catch (  BirtException e) {
    e.printStackTrace();
  }
  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 getSelectionChoicesForCascadingGroup(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();
  String valueType=requestedParam.getDataType();
  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 count=0;
    while (iter.next()) {
      String label=(labelExpr != null ? iter.getString(labelExpr) : null);
      Object value=iter.getValue(valueExpr);
      value=convertToType(value,valueType);
      choices.add(new SelectionChoice(label,value));
      count++;
      if ((listLimit != 0) && (count >= listLimit))       break;
      iter.skipToEnd(skipLevel);
    }
  }
 catch (  BirtException e) {
    e.printStackTrace();
  }
  if (!fixedOrder)   Collections.sort(choices,new SelectionChoiceComparator(true));
  return choices;
}