Program: 65190
Project: 65190
Buggy source:
protected void prepareQuery() throws DataException {
  try {
    IBinding[] bindings=null;
    if (this.queryDefn.getSourceQuery() instanceof SubqueryLocator) {
      this.queryResults=engine.getQueryResults(getParentQueryResultsID((SubqueryLocator)(queryDefn.getSourceQuery())));
      IQueryDefinition queryDefinition=queryResults.getPreparedQuery().getReportQueryDefn();
      if (queryDefn.getSourceQuery() instanceof SubqueryLocator) {
        ArrayList<IBinding> bindingList=new ArrayList<IBinding>();
        getSubQueryBindings(queryDefinition,((SubqueryLocator)queryDefn.getSourceQuery()).getName(),bindingList);
        addQueryBindings(bindingList,queryDefinition.getBindings());
        bindings=bindingList.toArray(new IBinding[0]);
      }
 else {
        bindings=(IBinding[])(queryDefinition.getBindings().values().toArray(new IBinding[0]));
      }
    }
 else {
      if (((IQueryDefinition)queryDefn.getSourceQuery()).getQueryResultsID() == null) {
        newPreDataEnige();
        this.queryResults=PreparedQueryUtil.newInstance(preDataEngine,(IQueryDefinition)queryDefn.getSourceQuery(),this.appContext).execute(null);
      }
 else {
        this.queryResults=PreparedQueryUtil.newInstance(engine,(IQueryDefinition)queryDefn.getSourceQuery(),this.appContext).execute(null);
      }
      if (queryResults != null && queryResults.getPreparedQuery() != null) {
        IQueryDefinition queryDefinition=queryResults.getPreparedQuery().getReportQueryDefn();
        bindings=(IBinding[])queryDefinition.getBindings().values().toArray(new IBinding[0]);
      }
 else {
        bindings=new IBinding[0];
      }
    }
    if (!hasBinding) {
      for (int i=0; i < bindings.length; i++) {
        IBinding binding=bindings[i];
        if (!this.queryDefn.getBindings().containsKey(binding.getBindingName()))         this.queryDefn.addBinding(new Binding(binding.getBindingName(),new ScriptExpression(ExpressionUtil.createJSDataSetRowExpression(binding.getBindingName()),binding.getDataType())));
      }
    }
  }
 catch (  BirtException e) {
    throw DataException.wrap(e);
  }
}

Fixed version (ground truth):
protected void prepareQuery() throws DataException {
  try {
    IBinding[] bindings=null;
    if (this.queryDefn.getSourceQuery() instanceof SubqueryLocator) {
      IQueryDefinition baseQueryDefn=getBaseQueryDefinition((SubqueryLocator)(queryDefn.getSourceQuery()));
      if (engine.getContext().getDocReader().exists(baseQueryDefn.getQueryResultsID() + "String_Node_Str" + DATA_STREAM_POST_FIX)) {
        this.queryResults=PreparedQueryUtil.newInstance(engine,baseQueryDefn,this.appContext).execute(null);
      }
 else       this.queryResults=engine.getQueryResults(baseQueryDefn.getQueryResultsID());
      IQueryDefinition queryDefinition=queryResults.getPreparedQuery().getReportQueryDefn();
      if (queryDefn.getSourceQuery() instanceof SubqueryLocator) {
        ArrayList<IBinding> bindingList=new ArrayList<IBinding>();
        getSubQueryBindings(queryDefinition,((SubqueryLocator)queryDefn.getSourceQuery()).getName(),bindingList);
        addQueryBindings(bindingList,queryDefinition.getBindings());
        bindings=bindingList.toArray(new IBinding[0]);
      }
 else {
        bindings=(IBinding[])(queryDefinition.getBindings().values().toArray(new IBinding[0]));
      }
    }
 else {
      if (((IQueryDefinition)queryDefn.getSourceQuery()).getQueryResultsID() == null) {
        newPreDataEnige();
        this.queryResults=PreparedQueryUtil.newInstance(preDataEngine,(IQueryDefinition)queryDefn.getSourceQuery(),this.appContext).execute(null);
      }
 else {
        this.queryResults=PreparedQueryUtil.newInstance(engine,(IQueryDefinition)queryDefn.getSourceQuery(),this.appContext).execute(null);
      }
      if (queryResults != null && queryResults.getPreparedQuery() != null) {
        IQueryDefinition queryDefinition=queryResults.getPreparedQuery().getReportQueryDefn();
        bindings=(IBinding[])queryDefinition.getBindings().values().toArray(new IBinding[0]);
      }
 else {
        bindings=new IBinding[0];
      }
    }
    if (!hasBinding) {
      for (int i=0; i < bindings.length; i++) {
        IBinding binding=bindings[i];
        if (!this.queryDefn.getBindings().containsKey(binding.getBindingName()))         this.queryDefn.addBinding(new Binding(binding.getBindingName(),new ScriptExpression(ExpressionUtil.createJSDataSetRowExpression(binding.getBindingName()),binding.getDataType())));
      }
    }
  }
 catch (  BirtException e) {
    throw DataException.wrap(e);
  }
}