Program: 76393
Project: 76393
Buggy source:
/** 
 * get selection choices from the data set.
 * @param dataSetName data set name
 * @param labelStmt label statement
 * @param valueStmt value statement
 * @param dataType value type
 * @return
 */
private Collection createDynamicSelectionChoices(String pattern,String dataSetName,String labelStmt,String valueStmt,String dataType,int limit,boolean fixedOrder){
  ArrayList choices=new ArrayList();
  ReportDesignHandle report=(ReportDesignHandle)this.runnable.getDesignHandle();
  DataSetHandle dataSet=report.findDataSet(dataSetName);
  if (dataSet != null) {
    try {
      IDataEngine dataEngine=executionContext.getDataEngine();
      DataRequestSession dteSession=getDataSession();
      dataEngine.defineDataSet(dataSet);
      ScriptExpression labelExpr=null;
      if (labelStmt != null && labelStmt.length() > 0) {
        labelExpr=new ScriptExpression(labelStmt);
      }
      ScriptExpression valueExpr=new ScriptExpression(valueStmt);
      QueryDefinition queryDefn=new QueryDefinition();
      queryDefn.setDataSetName(dataSetName);
      if (limit > 0) {
        queryDefn.setMaxRows(limit);
      }
      Iterator paramIter=dataSet.paramBindingsIterator();
      while (paramIter.hasNext()) {
        ParamBindingHandle binding=(ParamBindingHandle)paramIter.next();
        String paramName=binding.getParamName();
        String paramExpr=binding.getExpression();
        queryDefn.getInputParamBindings().add(new InputParameterBinding(paramName,new ScriptExpression(paramExpr)));
      }
      String labelColumnName=LABEL_PREFIX;
      ;
      String valueColumnName=VALUE_PREFIX;
      ;
      if (labelExpr != null) {
        queryDefn.addResultSetExpression(labelColumnName,labelExpr);
      }
      queryDefn.addResultSetExpression(valueColumnName,valueExpr);
      queryDefn.setAutoBinding(true);
      IPreparedQuery query=dteSession.prepare(queryDefn,getAppContext());
      IQueryResults result=query.execute(executionContext.getSharedScope());
      IResultIterator iter=result.getResultIterator();
      int count=0;
      Map checkPool=new HashMap();
      while (iter.next()) {
        String label=null;
        if (labelExpr != null) {
          label=iter.getString(labelColumnName);
        }
        Object value=iter.getValue(valueColumnName);
        value=convertToType(value,dataType);
        if (!checkPool.containsKey(value)) {
          checkPool.put(value,value);
          choices.add(new SelectionChoice(label,value));
          count++;
          if ((limit != 0) && (count >= limit)) {
            break;
          }
        }
      }
    }
 catch (    BirtException ex) {
      ex.printStackTrace();
    }
  }
  if (!fixedOrder)   Collections.sort(choices,new SelectionChoiceComparator(true,pattern,ULocale.forLocale(locale)));
  return choices;
}

Fixed version (ground truth):
/** 
 * get selection choices from the data set.
 * @param dataSetName data set name
 * @param labelStmt label statement
 * @param valueStmt value statement
 * @param dataType value type
 * @return
 */
private Collection createDynamicSelectionChoices(String pattern,String dataSetName,String labelStmt,String valueStmt,String dataType,int limit,boolean fixedOrder,boolean isDistinct,String sortDirection,String sortBy){
  boolean sortDirectionValue="String_Node_Str".equalsIgnoreCase(sortDirection);
  boolean sortByLabel="String_Node_Str".equalsIgnoreCase(sortBy);
  ArrayList choices=new ArrayList();
  ReportDesignHandle report=(ReportDesignHandle)this.runnable.getDesignHandle();
  DataSetHandle dataSet=report.findDataSet(dataSetName);
  if (dataSet != null) {
    try {
      IDataEngine dataEngine=executionContext.getDataEngine();
      DataRequestSession dteSession=getDataSession();
      dataEngine.defineDataSet(dataSet);
      ScriptExpression labelExpr=null;
      if (labelStmt != null && labelStmt.length() > 0) {
        labelExpr=new ScriptExpression(labelStmt);
      }
      ScriptExpression valueExpr=new ScriptExpression(valueStmt);
      QueryDefinition queryDefn=new QueryDefinition();
      queryDefn.setDataSetName(dataSetName);
      if (limit > 0) {
        queryDefn.setMaxRows(limit);
      }
      Iterator paramIter=dataSet.paramBindingsIterator();
      while (paramIter.hasNext()) {
        ParamBindingHandle binding=(ParamBindingHandle)paramIter.next();
        String paramName=binding.getParamName();
        String paramExpr=binding.getExpression();
        queryDefn.getInputParamBindings().add(new InputParameterBinding(paramName,new ScriptExpression(paramExpr)));
      }
      String labelColumnName=LABEL_PREFIX;
      ;
      String valueColumnName=VALUE_PREFIX;
      ;
      if (labelExpr != null) {
        queryDefn.addResultSetExpression(labelColumnName,labelExpr);
      }
      queryDefn.addResultSetExpression(valueColumnName,valueExpr);
      queryDefn.setAutoBinding(true);
      IPreparedQuery query=dteSession.prepare(queryDefn,getAppContext());
      IQueryResults result=query.execute(executionContext.getSharedScope());
      IResultIterator iter=result.getResultIterator();
      int count=0;
      Map checkPool=new HashMap();
      while (iter.next()) {
        String label=null;
        if (labelExpr != null) {
          label=iter.getString(labelColumnName);
        }
        Object value=iter.getValue(valueColumnName);
        value=convertToType(value,dataType);
        if (isDistinct) {
          if (!checkPool.containsKey(value)) {
            checkPool.put(value,value);
            choices.add(new SelectionChoice(label,value));
            count++;
          }
        }
 else {
          choices.add(new SelectionChoice(label,value));
          count++;
        }
        if ((limit != 0) && (count >= limit)) {
          break;
        }
      }
    }
 catch (    BirtException ex) {
      ex.printStackTrace();
    }
  }
  if (!fixedOrder)   Collections.sort(choices,new SelectionChoiceComparator(sortByLabel,pattern,sortDirectionValue,ULocale.forLocale(locale)));
  return choices;
}