Program: 69639
Project: 69639
Buggy source:
/** 
 * @throws BirtException
 */
private void genNestedQuery() throws BirtException {
  QueryDefinition qd=newReportQuery();
  IBaseExpression[] rowBeArray1=getRowExpr();
  IBaseExpression[] totalBeArray1=getAggrExpr();
  rowExprName=getRowExprName();
  totalExprName=getAggrExprName();
  prepareExprNameAndQuery(rowExprName,rowBeArray1,totalExprName,totalBeArray1,qd);
  IQueryResults qr=myGenDataEngine.prepare(qd).execute(scope);
  qr.getResultIterator().next();
  Context cx=Context.enter();
  ScriptableObject nestedScope=cx.initStandardObjects();
  nestedScope.setPrototype(this.scope);
  Context.exit();
  QueryDefinition nestedQD=newReportQuery();
  IBaseExpression[] tempArray2=getRowExpr();
  int length=tempArray2.length;
  IBaseExpression[] rowBeArray2=new IBaseExpression[length + 1];
  System.arraycopy(tempArray2,0,rowBeArray2,0,length);
  rowBeArray2[length]=new ScriptExpression("String_Node_Str");
  rowExprName=new String[rowBeArray2.length];
  for (int i=0; i < rowExprName.length; i++) {
    rowExprName[i]="String_Node_Str" + i;
  }
  IBaseExpression[] totalBeArray2=getAggrExpr();
  totalExprName=getAggrExprName();
  prepareExprNameAndQuery(rowExprName,rowBeArray2,totalExprName,totalBeArray2,nestedQD);
  IQueryResults qr2=myGenDataEngine.prepare(nestedQD).execute(qr,nestedScope);
  IResultIterator ri=qr2.getResultIterator();
  saveForPresentation(qr2,rowBeArray2,totalBeArray2);
  while (ri.next()) {
    for (int i=0; i < rowBeArray2.length; i++)     expectedValue.add(ri.getValue(rowExprName[i]));
    for (int i=0; i < totalBeArray2.length; i++)     expectedValue.add(ri.getValue(totalExprName[i]));
  }
  ri.close();
  qr2.close();
  qr.close();
  myGenDataEngine.shutdown();
}

Fixed version (ground truth):
/** 
 * @throws BirtException
 */
private void genNestedQuery() throws BirtException {
  QueryDefinition qd=newReportQuery();
  prepareExprNameAndQuery(qd);
  IQueryResults qr=myGenDataEngine.prepare(qd).execute(scope);
  qr.getResultIterator().next();
  Context cx=Context.enter();
  ScriptableObject nestedScope=cx.initStandardObjects();
  nestedScope.setPrototype(this.scope);
  Context.exit();
  QueryDefinition nestedQD=newReportQuery();
  IBaseExpression[] tempArray2=getRowExpr();
  int length=tempArray2.length;
  IBaseExpression[] rowBeArray2=new IBaseExpression[length + 1];
  System.arraycopy(tempArray2,0,rowBeArray2,0,length);
  rowBeArray2[length]=new ScriptExpression("String_Node_Str");
  rowExprName=new String[rowBeArray2.length];
  for (int i=0; i < rowExprName.length; i++) {
    rowExprName[i]="String_Node_Str" + i;
  }
  IBaseExpression[] totalBeArray2=getAggrExpr();
  IBinding total1=new Binding(this.totalExprName[0],totalBeArray2[0]);
  total1.setAggrFunction("String_Node_Str");
  IBinding total2=new Binding(this.totalExprName[1],totalBeArray2[1]);
  total2.setAggrFunction("String_Node_Str");
  nestedQD.addBinding(total1);
  nestedQD.addBinding(total2);
  for (int i=0; i < rowExprName.length; i++) {
    nestedQD.addBinding(new Binding(this.rowExprName[i],rowBeArray2[i]));
  }
  IQueryResults qr2=myGenDataEngine.prepare(nestedQD).execute(qr,nestedScope);
  IResultIterator ri=qr2.getResultIterator();
  saveForPresentation(qr2);
  while (ri.next()) {
    for (int i=0; i < rowBeArray2.length; i++)     expectedValue.add(ri.getValue(rowExprName[i]));
    for (int i=0; i < totalBeArray2.length; i++)     expectedValue.add(ri.getValue(totalExprName[i]));
  }
  ri.close();
  qr2.close();
  qr.close();
  myGenDataEngine.shutdown();
}