Program: 71957
Project: 71957
Buggy source:
/** 
 * @param dataEngine
 * @param queryDefn
 * @throws DataException
 */
PreparedIVQuerySourceQuery(DataEngineImpl dataEngine,IQueryDefinition queryDefn) throws DataException {
  super(dataEngine,queryDefn,null,null);
  Object[] params={dataEngine,queryDefn};
  logger.entering(PreparedIVDataSourceQuery.class.getName(),"String_Node_Str",params);
  this.queryDefn=queryDefn;
  this.engine=dataEngine;
  IBinding[] bindings=null;
  if (this.queryDefn.getSourceQuery() instanceof SubqueryLocator) {
    this.queryResults=engine.getQueryResults(getParentQueryResultsID((SubqueryLocator)(queryDefn.getSourceQuery())));
    IQueryDefinition queryDefinition=queryResults.getPreparedQuery().getReportQueryDefn();
    bindings=getSubQueryBindings(queryDefinition,((SubqueryLocator)queryDefn.getSourceQuery()).getName());
  }
 else {
    this.queryResults=engine.getQueryResults(((IQueryDefinition)queryDefn.getSourceQuery()).getQueryResultsID());
    IQueryDefinition queryDefinition=queryResults.getPreparedQuery().getReportQueryDefn();
    bindings=(IBinding[])queryDefinition.getBindings().values().toArray(new IBinding[0]);
  }
  for (int i=0; i < bindings.length; i++) {
    IBinding binding=bindings[i];
    this.queryDefn.addBinding(new Binding(binding.getBindingName(),new ScriptExpression(ExpressionUtil.createJSDataSetRowExpression(binding.getBindingName()),binding.getDataType())));
  }
  preparedQuery=new PreparedQuery(dataEngine.getSession(),dataEngine.getContext(),this.queryDefn,this,appContext);
  logger.exiting(PreparedIVDataSourceQuery.class.getName(),"String_Node_Str");
}

Fixed version (ground truth):
/** 
 * @param dataEngine
 * @param queryDefn
 * @throws DataException
 */
PreparedIVQuerySourceQuery(DataEngineImpl dataEngine,IQueryDefinition queryDefn) throws DataException {
  super(dataEngine,queryDefn,null,null);
  Object[] params={dataEngine,queryDefn};
  logger.entering(PreparedIVDataSourceQuery.class.getName(),"String_Node_Str",params);
  this.queryDefn=queryDefn;
  this.engine=dataEngine;
  IBinding[] bindings=null;
  if (this.queryDefn.getSourceQuery() instanceof SubqueryLocator) {
    this.queryResults=engine.getQueryResults(getParentQueryResultsID((SubqueryLocator)(queryDefn.getSourceQuery())));
    IQueryDefinition queryDefinition=queryResults.getPreparedQuery().getReportQueryDefn();
    bindings=getSubQueryBindings(queryDefinition,((SubqueryLocator)queryDefn.getSourceQuery()).getName());
  }
 else {
    this.queryResults=engine.getQueryResults(((IQueryDefinition)queryDefn.getSourceQuery()).getQueryResultsID());
    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];
    }
  }
  for (int i=0; i < bindings.length; i++) {
    IBinding binding=bindings[i];
    this.queryDefn.addBinding(new Binding(binding.getBindingName(),new ScriptExpression(ExpressionUtil.createJSDataSetRowExpression(binding.getBindingName()),binding.getDataType())));
  }
  preparedQuery=new PreparedQuery(dataEngine.getSession(),dataEngine.getContext(),this.queryDefn,this,appContext);
  logger.exiting(PreparedIVDataSourceQuery.class.getName(),"String_Node_Str");
}