Program: 12959
Project: 12959
Buggy source:
/** 
 * Execute a Query
 * @param queryParam the query
 * @param resultFormatParam the format to return the results in ('RS_TEXT' default for select queries / 'RDF/XML'default for construct/describe queries)
 * @param output output stream to write to - null uses System.out
 * @param datasetMode run against dataset rather than model
 * @throws IOException error writing to output
 */
public void executeQuery(String queryParam,String resultFormatParam,OutputStream output,boolean datasetMode) throws IOException {
  OutputStream out=(output != null) ? output : System.out;
  QueryExecution qe=null;
  try {
    Query query=QueryFactory.create(queryParam,Syntax.syntaxARQ);
    if (datasetMode) {
      qe=QueryExecutionFactory.create(query,getDataset());
    }
 else {
      qe=QueryExecutionFactory.create(query,getJenaModel());
    }
    if (query.isSelectType()) {
      ResultSetFormat rsf=formatSymbols.get(resultFormatParam);
      if (rsf == null) {
        rsf=ResultSetFormat.syntaxText;
      }
      ResultSetFormatter.output(out,qe.execSelect(),rsf);
    }
 else     if (query.isAskType()) {
      out.write((Boolean.toString(qe.execAsk()) + "String_Node_Str").getBytes());
    }
 else {
      Model resultModel=null;
      if (query.isConstructType()) {
        resultModel=qe.execConstruct();
      }
 else       if (query.isDescribeType()) {
        resultModel=qe.execDescribe();
      }
 else {
        throw new IllegalArgumentException("String_Node_Str");
      }
      resultModel.write(out,resultFormatParam);
    }
  }
 catch (  QueryParseException e1) {
    try {
      executeUpdateQuery(queryParam,datasetMode);
      log.info("String_Node_Str");
    }
 catch (    QueryParseException e2) {
      log.error("String_Node_Str" + queryParam);
      log.trace("String_Node_Str",e1);
      log.trace("String_Node_Str",e2);
    }
  }
 finally {
    if (qe != null) {
      qe.close();
    }
  }
}

Fixed version (ground truth):
/** 
 * Execute a Query
 * @param queryParam the query
 * @param resultFormatParam the format to return the results in ('RS_TEXT' default for select queries / 'RDF/XML'default for construct/describe queries)
 * @param output output stream to write to - null uses System.out
 * @param datasetMode run against dataset rather than model
 * @throws IOException error writing to output
 */
public void executeQuery(String queryParam,String resultFormatParam,OutputStream output,boolean datasetMode) throws IOException {
  OutputStream out=(output != null) ? output : System.out;
  QueryExecution qe=null;
  try {
    Query query=QueryFactory.create(queryParam,Syntax.syntaxARQ);
    if (datasetMode) {
      qe=QueryExecutionFactory.create(query,getDataset());
    }
 else {
      qe=QueryExecutionFactory.create(query,getJenaModel());
    }
    if (query.isSelectType()) {
      ResultSetFormat rsf=formatSymbols.get(resultFormatParam);
      if (rsf == null) {
        rsf=ResultSetFormat.syntaxText;
      }
      ResultSetFormatter.output(out,qe.execSelect(),rsf);
    }
 else     if (query.isAskType()) {
      out.write((Boolean.toString(qe.execAsk()) + "String_Node_Str").getBytes());
    }
 else {
      Model resultModel=null;
      if (query.isConstructType()) {
        resultModel=qe.execConstruct();
      }
 else       if (query.isDescribeType()) {
        resultModel=qe.execDescribe();
      }
 else {
        throw new IllegalArgumentException("String_Node_Str");
      }
      exportRdfToStream(resultModel,out,resultFormatParam);
    }
  }
 catch (  QueryParseException e1) {
    try {
      executeUpdateQuery(queryParam,datasetMode);
      log.info("String_Node_Str");
    }
 catch (    QueryParseException e2) {
      log.error("String_Node_Str" + queryParam);
      log.trace("String_Node_Str",e1);
      log.trace("String_Node_Str",e2);
    }
  }
 finally {
    if (qe != null) {
      qe.close();
    }
  }
}