Program: 86402
Project: 86402
Buggy source:
private Response handleQuery(Request req,UriInfo uriInfo,String queryString,List<String> defgraphs,List<String> namedgraphs,String inference){
  SailRepositoryConnection conn=null;
  try {
    if (queryString == null) {
      throw new MalformedQueryException("String_Node_Str");
    }
    conn=getConnection();
    final Query query;
    if (inference != null && inference.equals("String_Node_Str")) {
      QueryRewriter qw=qwfactory.getRewriter(conn);
      query=qw.rewrite(QueryLanguage.SPARQL,queryString,uriInfo.getAbsolutePath().toASCIIString());
    }
 else {
      query=conn.prepareQuery(QueryLanguage.SPARQL,queryString,uriInfo.getAbsolutePath().toASCIIString());
    }
    query.setMaxQueryTime(timeout);
    final List<Variant> acceptable;
    boolean isGraphQuery=false;
    if (query instanceof GraphQuery) {
      acceptable=rdfResultVariants;
      isGraphQuery=true;
    }
 else {
      acceptable=queryResultVariants;
    }
    final Variant variant=req.selectVariant(acceptable);
    if (variant == null) {
      return Response.notAcceptable(acceptable).build();
    }
    final MediaType mt=variant.getMediaType();
    final String mtstr=mt.getType() + "String_Node_Str" + mt.getSubtype();
    StreamingOutput stream;
    RDFWriterFactory factory=registry.get(getRDFFormat(mtstr));
    if (isGraphQuery) {
      GraphQuery gq=(GraphQuery)query;
      stream=new SPARQLGraphStreamingOutput(gq,factory,conn);
    }
 else {
      TupleQuery tq=(TupleQuery)query;
      stream=new SPARQLResultStreamingOutput(tq,getResultWriterFactory(mtstr),conn);
    }
    return Response.ok(stream).type(mt).build();
  }
 catch (  MalformedQueryException ex) {
    close(conn,ex);
    String str=ex.getMessage();
    return Response.status(Response.Status.BAD_REQUEST).entity(str.getBytes(Charset.forName("String_Node_Str"))).build();
  }
catch (  RepositoryException ex) {
    close(conn,ex);
    throw new WebApplicationException(ex);
  }
}

Fixed version (ground truth):
private Response handleQuery(Request req,UriInfo uriInfo,String queryString,List<String> defgraphs,List<String> namedgraphs,String inference){
  SailRepositoryConnection conn=null;
  try {
    if (queryString == null) {
      throw new MalformedQueryException("String_Node_Str");
    }
    conn=getConnection();
    final Query query;
    if (inference != null && inference.equals("String_Node_Str")) {
      QueryRewriter qw=qwfactory.getRewriter(conn);
      query=qw.rewrite(QueryLanguage.SPARQL,queryString,uriInfo.getAbsolutePath().toASCIIString());
    }
 else {
      query=conn.prepareQuery(QueryLanguage.SPARQL,queryString,uriInfo.getAbsolutePath().toASCIIString());
    }
    query.setMaxQueryTime(timeout);
    final List<Variant> acceptable;
    boolean isGraphQuery=false;
    boolean isBooleanQuery=false;
    if (query instanceof GraphQuery) {
      isGraphQuery=true;
    }
 else     if (query instanceof BooleanQuery) {
      isBooleanQuery=true;
    }
    if (isGraphQuery) {
      acceptable=rdfResultVariants;
    }
 else     if (isBooleanQuery) {
      acceptable=booleanResultVariants;
    }
 else {
      acceptable=queryResultVariants;
    }
    final Variant variant=req.selectVariant(acceptable);
    if (variant == null) {
      return Response.notAcceptable(acceptable).build();
    }
    final MediaType mt=variant.getMediaType();
    final String mtstr=mt.getType() + "String_Node_Str" + mt.getSubtype();
    StreamingOutput stream;
    RDFWriterFactory factory=registry.get(getRDFFormat(mtstr));
    if (isGraphQuery) {
      GraphQuery gq=(GraphQuery)query;
      stream=new SPARQLGraphStreamingOutput(gq,factory,conn);
    }
 else     if (isBooleanQuery) {
      BooleanQuery bq=(BooleanQuery)query;
      stream=new SPARQLBooleanStreamingOutput(bq,getBooleanWriterFactory(mtstr),conn);
    }
 else {
      TupleQuery tq=(TupleQuery)query;
      stream=new SPARQLTupleStreamingOutput(tq,getTupleWriterFactory(mtstr),conn);
    }
    return Response.ok(stream).type(mt).build();
  }
 catch (  MalformedQueryException ex) {
    close(conn,ex);
    String str=ex.getMessage();
    return Response.status(Response.Status.BAD_REQUEST).entity(str.getBytes(Charset.forName("String_Node_Str"))).build();
  }
catch (  RepositoryException ex) {
    close(conn,ex);
    throw new WebApplicationException(ex);
  }
}