Program: 74004
Project: 74004
Buggy source:
/** 
 * IV request is applied here
 * @return query definition for interactive viewing
 */
private QueryDefinition newPreIVReportQuery(int filterNeeded,boolean sortNeeded,int groupNeeded,int mode){
  QueryDefinition qd=new QueryDefinition();
  IBaseExpression[] rowBeArray=getRowExpr();
  IBaseExpression[] totalBeArray=getAggrExpr();
  for (int i=0; i < rowBeArray.length; i++)   qd.addResultSetExpression(this.rowExprName[i],rowBeArray[i]);
  for (int i=0; i < totalBeArray.length; i++)   qd.addResultSetExpression(this.totalExprName[i],totalBeArray[i]);
  if (this.updateNewBindingName != null && this.updateNewBindingName.trim().length() > 0) {
    qd.addResultSetExpression(this.updateNewBindingName,this.updateNewBindingExpr);
  }
  if (mode == UPDATE) {
    qd.getFilters().addAll(this.GEN_filterDefn);
  }
 else   if (mode == PRESENTATION) {
    if (PRE_basedon_genfilter == false)     qd.getFilters().addAll(UPDATE_filterDefn);
 else     qd.getFilters().addAll(GEN_filterDefn);
  }
  if (filterNeeded == 0) {
    ScriptExpression filterExpr=new ScriptExpression("String_Node_Str");
    FilterDefinition fd=new FilterDefinition(filterExpr);
    qd.addFilter(fd);
  }
  if (filterNeeded == 1) {
    ScriptExpression filterExpr=new ScriptExpression("String_Node_Str");
    FilterDefinition fd=new FilterDefinition(filterExpr);
    qd.addFilter(fd);
    filterExpr=new ScriptExpression("String_Node_Str");
    fd=new FilterDefinition(filterExpr);
    qd.addFilter(fd);
  }
  if (filterNeeded == 2) {
    ScriptExpression filterExpr=new ScriptExpression("String_Node_Str");
    FilterDefinition fd=new FilterDefinition(filterExpr);
    qd.addFilter(fd);
    filterExpr=new ScriptExpression("String_Node_Str");
    fd=new FilterDefinition(filterExpr);
    qd.addFilter(fd);
  }
  if (filterNeeded == 3) {
    ScriptExpression filterExpr=new ScriptExpression("String_Node_Str");
    FilterDefinition fd=new FilterDefinition(filterExpr);
    qd.addFilter(fd);
    filterExpr=new ScriptExpression("String_Node_Str");
    fd=new FilterDefinition(filterExpr);
    qd.addFilter(fd);
  }
  if (filterNeeded == 4) {
    BaseExpression filterExpr=new ConditionalExpression("String_Node_Str",IConditionalExpression.OP_EQ,"String_Node_Str" + TimeZone.getDefault().getRawOffset() / 3600000 + "String_Node_Str");
    FilterDefinition fd=new FilterDefinition(filterExpr);
    qd.addFilter(fd);
  }
  if (filterNeeded == 5) {
    ConditionalExpression filterExpr=new ConditionalExpression("String_Node_Str",IConditionalExpression.OP_TOP_N,"String_Node_Str");
    FilterDefinition fd=new FilterDefinition(filterExpr);
    qd.addFilter(fd);
  }
  UPDATE_filterDefn=qd.getFilters();
  if (sortNeeded) {
    SortDefinition sd=new SortDefinition();
    sd.setExpression("String_Node_Str");
    sd.setSortDirection(ISortDefinition.SORT_ASC);
    qd.addSort(sd);
  }
  if (groupNeeded == 1 || groupNeeded == 0) {
    GroupDefinition gd=null;
    if (groupNeeded == 1) {
      gd=new GroupDefinition("String_Node_Str");
      gd.setKeyColumn("String_Node_Str");
      qd.addGroup(gd);
    }
 else     if (groupNeeded == 0) {
      gd=new GroupDefinition();
      gd.setKeyColumn("String_Node_Str");
      qd.addGroup(gd);
    }
    if (this.UPDATE_add_subquery == 1) {
      SubqueryDefinition subqueryDefn=new SubqueryDefinition(subQueryName1,qd);
      subRowExprName1=new String[3];
      subRowExprName1[0]="String_Node_Str";
      subRowExprName1[1]="String_Node_Str";
      subRowExprName1[2]="String_Node_Str";
      ScriptExpression[] exprs=new ScriptExpression[3];
      exprs[0]=new ScriptExpression("String_Node_Str");
      exprs[1]=new ScriptExpression("String_Node_Str");
      exprs[2]=new ScriptExpression("String_Node_Str");
      for (int i=0; i < subRowExprName1.length; i++)       subqueryDefn.addResultSetExpression(subRowExprName1[i],exprs[i]);
      if (this.USE_DATE_IN_SUBQUERY)       subqueryDefn.addResultSetExpression("String_Node_Str",new ScriptExpression("String_Node_Str"));
      subqueryDefn.setApplyOnGroupFlag(true);
      gd.addSubquery(subqueryDefn);
    }
    if (this.UPDATE_add_subquery == 2) {
      SubqueryDefinition subqueryDefn=new SubqueryDefinition(subQueryName2,qd);
      subRowExprName2=new String[2];
      subRowExprName2[0]="String_Node_Str";
      subRowExprName2[1]="String_Node_Str";
      ScriptExpression[] exprs=new ScriptExpression[2];
      exprs[0]=new ScriptExpression("String_Node_Str");
      exprs[1]=new ScriptExpression("String_Node_Str");
      for (int i=0; i < subRowExprName2.length; i++)       subqueryDefn.addResultSetExpression(subRowExprName2[i],exprs[i]);
      subqueryDefn.setApplyOnGroupFlag(true);
      gd.addSubquery(subqueryDefn);
    }
  }
  return qd;
}

Fixed version (ground truth):
/** 
 * IV request is applied here
 * @return query definition for interactive viewing
 */
private QueryDefinition newPreIVReportQuery(int filterNeeded,boolean sortNeeded,int groupNeeded,int mode){
  QueryDefinition qd=new QueryDefinition();
  IBaseExpression[] rowBeArray=getRowExpr();
  IBaseExpression[] totalBeArray=getAggrExpr();
  for (int i=0; i < rowBeArray.length; i++)   qd.addResultSetExpression(this.rowExprName[i],rowBeArray[i]);
  for (int i=0; i < totalBeArray.length; i++)   qd.addResultSetExpression(this.totalExprName[i],totalBeArray[i]);
  if (this.updateNewBindingName != null && this.updateNewBindingName.trim().length() > 0) {
    qd.addResultSetExpression(this.updateNewBindingName,this.updateNewBindingExpr);
  }
  if (mode == UPDATE) {
    qd.getFilters().addAll(this.GEN_filterDefn);
  }
 else   if (mode == PRESENTATION) {
    if (PRE_basedon_genfilter == false)     qd.getFilters().addAll(UPDATE_filterDefn);
 else     qd.getFilters().addAll(GEN_filterDefn);
  }
  if (filterNeeded == 0) {
    ScriptExpression filterExpr=new ScriptExpression("String_Node_Str");
    FilterDefinition fd=new FilterDefinition(filterExpr);
    qd.addFilter(fd);
  }
  if (filterNeeded == 1) {
    ScriptExpression filterExpr=new ScriptExpression("String_Node_Str");
    FilterDefinition fd=new FilterDefinition(filterExpr);
    qd.addFilter(fd);
    filterExpr=new ScriptExpression("String_Node_Str");
    fd=new FilterDefinition(filterExpr);
    qd.addFilter(fd);
  }
  if (filterNeeded == 2) {
    ScriptExpression filterExpr=new ScriptExpression("String_Node_Str");
    FilterDefinition fd=new FilterDefinition(filterExpr);
    qd.addFilter(fd);
    filterExpr=new ScriptExpression("String_Node_Str");
    fd=new FilterDefinition(filterExpr);
    qd.addFilter(fd);
  }
  if (filterNeeded == 3) {
    ScriptExpression filterExpr=new ScriptExpression("String_Node_Str");
    FilterDefinition fd=new FilterDefinition(filterExpr);
    qd.addFilter(fd);
    filterExpr=new ScriptExpression("String_Node_Str");
    fd=new FilterDefinition(filterExpr);
    qd.addFilter(fd);
  }
  if (filterNeeded == 4) {
    BaseExpression filterExpr=new ConditionalExpression("String_Node_Str",IConditionalExpression.OP_EQ,"String_Node_Str" + TimeZone.getDefault().getRawOffset() / 3600000 + "String_Node_Str");
    FilterDefinition fd=new FilterDefinition(filterExpr);
    qd.addFilter(fd);
  }
  if (filterNeeded == 5) {
    ConditionalExpression filterExpr=new ConditionalExpression("String_Node_Str",IConditionalExpression.OP_TOP_N,"String_Node_Str");
    FilterDefinition fd=new FilterDefinition(filterExpr);
    qd.addFilter(fd);
  }
  if (filterNeeded == 6) {
    ScriptExpression filterExpr=new ScriptExpression("String_Node_Str");
    FilterDefinition fd=new FilterDefinition(filterExpr);
    qd.addFilter(fd);
  }
  UPDATE_filterDefn=qd.getFilters();
  if (sortNeeded) {
    SortDefinition sd=new SortDefinition();
    sd.setExpression("String_Node_Str");
    sd.setSortDirection(ISortDefinition.SORT_ASC);
    qd.addSort(sd);
  }
  if (groupNeeded == 1 || groupNeeded == 0) {
    GroupDefinition gd=null;
    if (groupNeeded == 1) {
      gd=new GroupDefinition("String_Node_Str");
      gd.setKeyColumn("String_Node_Str");
      qd.addGroup(gd);
    }
 else     if (groupNeeded == 0) {
      gd=new GroupDefinition();
      gd.setKeyColumn("String_Node_Str");
      qd.addGroup(gd);
    }
    if (this.UPDATE_add_subquery == 1) {
      SubqueryDefinition subqueryDefn=getSubQueryDefn(qd);
      gd.addSubquery(subqueryDefn);
    }
    if (this.UPDATE_add_subquery == 2) {
      SubqueryDefinition subqueryDefn=new SubqueryDefinition(subQueryName2,qd);
      subRowExprName2=new String[2];
      subRowExprName2[0]="String_Node_Str";
      subRowExprName2[1]="String_Node_Str";
      ScriptExpression[] exprs=new ScriptExpression[2];
      exprs[0]=new ScriptExpression("String_Node_Str");
      exprs[1]=new ScriptExpression("String_Node_Str");
      for (int i=0; i < subRowExprName2.length; i++)       subqueryDefn.addResultSetExpression(subRowExprName2[i],exprs[i]);
      subqueryDefn.setApplyOnGroupFlag(true);
      gd.addSubquery(subqueryDefn);
    }
  }
  if (add_subquery_on_query) {
    qd.addSubquery(getSubQueryDefn(qd));
  }
  return qd;
}