Program: 79051
Project: 79051
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 dataSetName,String labelStmt,String valueStmt,String dataType){
  ArrayList choices=new ArrayList();
  ReportDesignHandle report=(ReportDesignHandle)this.runnable.getDesignHandle();
  DataSetHandle dataSet=report.findDataSet(dataSetName);
  if (dataSet != null) {
    try {
      DataEngine dataEngine=getDataEngine();
      DataSourceHandle dataSource=dataSet.getDataSource();
      try {
        dataEngine.defineDataSource(ModelDteApiAdapter.getInstance().createDataSourceDesign(dataSource));
        dataEngine.defineDataSet(ModelDteApiAdapter.getInstance().createDataSetDesign(dataSet));
      }
 catch (      BirtException e) {
        log.log(Level.SEVERE,e.getMessage());
      }
      ScriptExpression labelExpr=new ScriptExpression(labelStmt);
      ScriptExpression valueExpr=new ScriptExpression(valueStmt);
      QueryDefinition queryDefn=new QueryDefinition();
      queryDefn.setDataSetName(dataSetName);
      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)));
      }
      queryDefn.getRowExpressions().add(labelExpr);
      queryDefn.getRowExpressions().add(valueExpr);
      GroupDefinition groupDef=new GroupDefinition();
      groupDef.setKeyExpression(valueStmt);
      queryDefn.addGroup(groupDef);
      IPreparedQuery query=dataEngine.prepare(queryDefn);
      IQueryResults result=query.execute(executionContext.getSharedScope());
      IResultIterator iter=result.getResultIterator();
      while (iter.next()) {
        String label=iter.getString(labelExpr);
        Object value=iter.getValue(valueExpr);
        choices.add(new SelectionChoice(label,convertToType(value,dataType)));
        iter.skipToEnd(1);
      }
    }
 catch (    BirtException ex) {
      ex.printStackTrace();
    }
  }
  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 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 {
      DataEngine dataEngine=getDataEngine();
      DataSourceHandle dataSource=dataSet.getDataSource();
      try {
        dataEngine.defineDataSource(ModelDteApiAdapter.getInstance().createDataSourceDesign(dataSource));
        dataEngine.defineDataSet(ModelDteApiAdapter.getInstance().createDataSetDesign(dataSet));
      }
 catch (      BirtException e) {
        log.log(Level.SEVERE,e.getMessage());
      }
      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);
      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)));
      }
      if (labelExpr != null) {
        queryDefn.getRowExpressions().add(labelExpr);
      }
      queryDefn.getRowExpressions().add(valueExpr);
      GroupDefinition groupDef=new GroupDefinition();
      groupDef.setKeyExpression(valueStmt);
      queryDefn.addGroup(groupDef);
      IPreparedQuery query=dataEngine.prepare(queryDefn);
      IQueryResults result=query.execute(executionContext.getSharedScope());
      IResultIterator iter=result.getResultIterator();
      int count=0;
      while (iter.next()) {
        String label=null;
        if (labelExpr != null) {
          label=iter.getString(labelExpr);
        }
        Object value=iter.getValue(valueExpr);
        choices.add(new SelectionChoice(label,convertToType(value,dataType)));
        count++;
        if ((limit != 0) && (count >= limit)) {
          break;
        }
        iter.skipToEnd(1);
      }
    }
 catch (    BirtException ex) {
      ex.printStackTrace();
    }
  }
  if (!fixedOrder)   Collections.sort(choices,new SelectionChoiceComparator(true));
  return choices;
}