Program: 72122
Project: 72122
Buggy source:
/** 
 * @param parentQuery parent query
 * @param design current root design
 * @return queries array of this design
 */
public IDataQueryDefinition[] build(IDataQueryDefinition parentQuery,ReportItemDesign design){
synchronized (report) {
    Object result=design.accept(queryBuilder,parentQuery);
    if (result == null) {
      return null;
    }
    IDataQueryDefinition[] queries=(IDataQueryDefinition[])result;
    design.setQueries(queries);
    if (!design.useCachedResult()) {
      for (int i=0; i < queries.length; i++) {
        IDataQueryDefinition query=queries[i];
        if (query != null) {
          String queryId=String.valueOf(design.getID());
          if (i > 0) {
            queryId=queryId + "String_Node_Str" + String.valueOf(i);
          }
          query.setName(queryId);
          this.queryIDs.put(query,queryId);
          if (query instanceof IBaseQueryDefinition) {
            IBaseQueryDefinition baseQuery=(IBaseQueryDefinition)query;
            ResultMetaData metaData=new ResultMetaData(baseQuery);
            resultMetaData.put(baseQuery,metaData);
          }
          registerQueryAndElement(query,design);
          if (!(query instanceof ISubqueryDefinition)) {
            this.queries.add(query);
          }
 else           if (query instanceof ISubqueryDefinition) {
            if (!(parentQuery instanceof IBaseQueryDefinition)) {
              context.addException(design.getHandle(),new EngineException(MessageConstants.SUBQUERY_CREATE_ERROR,design.getID()));
            }
            IBaseQueryDefinition pQuery=(IBaseQueryDefinition)parentQuery;
            Collection subQueries=pQuery.getSubqueries();
            if (!subQueries.contains(query)) {
              subQueries.add(query);
            }
          }
        }
      }
      registerQueryToHandle(design,queries);
      resolveQueryReference(design,queries);
      return queries;
    }
 else {
      for (int i=0; i < queries.length; i++) {
        IDataQueryDefinition query=queries[i];
        if (query instanceof IBaseQueryDefinition) {
          IBaseQueryDefinition baseQuery=(IBaseQueryDefinition)query;
          ResultMetaData metaData=new ResultMetaData(baseQuery);
          resultMetaData.put(baseQuery,metaData);
        }
      }
      registerQueryToHandle(design,queries);
      return null;
    }
  }
}

Fixed version (ground truth):
/** 
 * @param parentQuery parent query
 * @param design current root design
 * @return queries array of this design
 */
public IDataQueryDefinition[] build(IDataQueryDefinition parentQuery,ReportItemDesign design){
synchronized (report) {
    Object result=design.accept(queryBuilder,parentQuery);
    if (result == null) {
      return null;
    }
    IDataQueryDefinition[] queries=(IDataQueryDefinition[])result;
    design.setQueries(queries);
    if (!design.useCachedResult()) {
      for (int i=0; i < queries.length; i++) {
        IDataQueryDefinition query=queries[i];
        if (query != null) {
          String queryId=String.valueOf(design.getID());
          if (i > 0) {
            queryId=queryId + "String_Node_Str" + String.valueOf(i);
          }
          if (query instanceof IQueryDefinition) {
            query.setName(queryId);
          }
          this.queryIDs.put(query,queryId);
          if (query instanceof IBaseQueryDefinition) {
            IBaseQueryDefinition baseQuery=(IBaseQueryDefinition)query;
            ResultMetaData metaData=new ResultMetaData(baseQuery);
            resultMetaData.put(baseQuery,metaData);
          }
          registerQueryAndElement(query,design);
          if (!(query instanceof ISubqueryDefinition)) {
            this.queries.add(query);
          }
 else           if (query instanceof ISubqueryDefinition) {
            if (!(parentQuery instanceof IBaseQueryDefinition)) {
              context.addException(design.getHandle(),new EngineException(MessageConstants.SUBQUERY_CREATE_ERROR,design.getID()));
            }
            IBaseQueryDefinition pQuery=(IBaseQueryDefinition)parentQuery;
            Collection subQueries=pQuery.getSubqueries();
            if (!subQueries.contains(query)) {
              subQueries.add(query);
            }
          }
        }
      }
      registerQueryToHandle(design,queries);
      resolveQueryReference(design,queries);
      return queries;
    }
 else {
      for (int i=0; i < queries.length; i++) {
        IDataQueryDefinition query=queries[i];
        if (query instanceof IBaseQueryDefinition) {
          IBaseQueryDefinition baseQuery=(IBaseQueryDefinition)query;
          ResultMetaData metaData=new ResultMetaData(baseQuery);
          resultMetaData.put(baseQuery,metaData);
        }
      }
      registerQueryToHandle(design,queries);
      return null;
    }
  }
}