Program: 9838
Project: 9838
Buggy source:
@Override protected Binding prefetch() throws Exception {
  if (!rs.next()) {
    return super.finish();
  }
  ResultSetMetaData meta=rs.getMetaData();
  BindingMap binding=new BindingHashMap();
  for (int i=1; i <= meta.getColumnCount(); ++i) {
    String colName=meta.getColumnLabel(i);
    Object colValue=rs.getObject(i);
    NodeValue nodeValue;
    if (colValue instanceof Date) {
      String tmp=colValue.toString();
      nodeValue=NodeValue.makeDate(tmp);
    }
 else     if (colValue instanceof Timestamp) {
      String tmp=colValue.toString();
      String val=tmp.replace(' ','T');
      nodeValue=NodeValue.makeDateTime(val);
    }
 else {
      nodeValue=MakeNodeValue.makeNodeValue(colValue);
    }
    if (nodeValue == null) {
      continue;
    }
    Node node=nodeValue.asNode();
    Var indexVar=Var.alloc("String_Node_Str" + i);
    binding.add(indexVar,node);
    Var colVar=Var.alloc(colName);
    if (!binding.contains(colVar)) {
      binding.add(colVar,node);
    }
  }
  boolean debugMode=true;
  BindingMap result=new BindingHashMap();
  for (  Entry<Var,Collection<RestrictedExpr>> entry : sparqlVarMap.asMap().entrySet()) {
    Var bindingVar=entry.getKey();
    Collection<RestrictedExpr> candidateExprs=entry.getValue();
    NodeValue value=null;
    Set<Var> usedVars=new HashSet<Var>();
    for (    RestrictedExpr def : candidateExprs) {
      Expr expr=def.getExpr();
      boolean allBound=true;
      Set<Var> exprVars=expr.getVarsMentioned();
      for (      Var var : exprVars) {
        if (!binding.contains(var)) {
          allBound=false;
          break;
        }
      }
      if (allBound) {
        if (value != null) {
          if (usedVars.containsAll(expr.getVarsMentioned())) {
            continue;
          }
 else           if (usedVars.equals(expr.getVarsMentioned())) {
            throw new RuntimeException("String_Node_Str" + bindingVar + "String_Node_Str"+ entry.getValue());
          }
 else           if (!expr.getVarsMentioned().containsAll(usedVars)) {
            throw new RuntimeException("String_Node_Str" + bindingVar + "String_Node_Str"+ entry.getValue());
          }
        }
        expr=MakeExprPermissive.getInstance().deepCopy(expr);
        value=ExprUtils.eval(expr,binding);
        if (!debugMode) {
          break;
        }
      }
    }
    Node resultValue=value == null ? null : value.asNode();
    if (resultValue == null) {
      logger.trace("String_Node_Str" + bindingVar + "String_Node_Str");
    }
 else {
      boolean isDatatypeCanonicalization=false;
      Node canonResultValue=canonicalizer.convert(resultValue);
      if (!isDatatypeCanonicalization) {
        if (canonResultValue.isLiteral()) {
          String lex=canonResultValue.getLiteralLexicalForm();
          if (resultValue.isLiteral()) {
            RDFDatatype originalType=resultValue.getLiteralDatatype();
            if (originalType != null) {
              canonResultValue=Node.createLiteral(lex,originalType);
            }
          }
 else {
            throw new RuntimeException("String_Node_Str" + resultValue + "String_Node_Str"+ canonResultValue);
          }
        }
      }
      result.add(bindingVar,canonResultValue);
    }
  }
  return result;
}

Fixed version (ground truth):
@Override protected Binding prefetch() throws Exception {
  if (!rs.next()) {
    return super.finish();
  }
  ResultSetMetaData meta=rs.getMetaData();
  BindingMap binding=new BindingHashMap();
  for (int i=1; i <= meta.getColumnCount(); ++i) {
    String colName=meta.getColumnLabel(i);
    Object colValue=rs.getObject(i);
    NodeValue nodeValue;
    if (colValue instanceof Date) {
      String tmp=colValue.toString();
      nodeValue=NodeValue.makeDate(tmp);
    }
 else     if (colValue instanceof Timestamp) {
      String tmp=colValue.toString();
      String val=tmp.replace(' ','T');
      nodeValue=NodeValue.makeDateTime(val);
    }
 else {
      nodeValue=MakeNodeValue.makeNodeValue(colValue);
    }
    if (nodeValue == null) {
      continue;
    }
    Node node=nodeValue.asNode();
    Var indexVar=Var.alloc("String_Node_Str" + i);
    binding.add(indexVar,node);
    Var colVar=Var.alloc(colName);
    if (!binding.contains(colVar)) {
      binding.add(colVar,node);
    }
  }
  if (rowIdVar != null) {
    long rowId=nextRowId++;
    Node node=NodeValue.makeInteger(rowId).asNode();
    binding.add(rowIdVar,node);
  }
  boolean debugMode=true;
  BindingMap result=new BindingHashMap();
  for (  Entry<Var,Collection<RestrictedExpr>> entry : sparqlVarMap.asMap().entrySet()) {
    Var bindingVar=entry.getKey();
    Collection<RestrictedExpr> candidateExprs=entry.getValue();
    NodeValue value=null;
    Set<Var> usedVars=new HashSet<Var>();
    for (    RestrictedExpr def : candidateExprs) {
      Expr expr=def.getExpr();
      boolean allBound=true;
      Set<Var> exprVars=expr.getVarsMentioned();
      for (      Var var : exprVars) {
        if (!binding.contains(var)) {
          allBound=false;
          break;
        }
      }
      if (allBound) {
        if (value != null) {
          if (usedVars.containsAll(expr.getVarsMentioned())) {
            continue;
          }
 else           if (usedVars.equals(expr.getVarsMentioned())) {
            throw new RuntimeException("String_Node_Str" + bindingVar + "String_Node_Str"+ entry.getValue());
          }
 else           if (!expr.getVarsMentioned().containsAll(usedVars)) {
            throw new RuntimeException("String_Node_Str" + bindingVar + "String_Node_Str"+ entry.getValue());
          }
        }
        expr=MakeExprPermissive.getInstance().deepCopy(expr);
        value=ExprUtils.eval(expr,binding);
        if (!debugMode) {
          break;
        }
      }
    }
    Node resultValue=value == null ? null : value.asNode();
    if (resultValue == null) {
      logger.trace("String_Node_Str" + bindingVar + "String_Node_Str");
    }
 else {
      boolean isDatatypeCanonicalization=false;
      Node canonResultValue=canonicalizer.convert(resultValue);
      if (!isDatatypeCanonicalization) {
        if (canonResultValue.isLiteral()) {
          String lex=canonResultValue.getLiteralLexicalForm();
          if (resultValue.isLiteral()) {
            RDFDatatype originalType=resultValue.getLiteralDatatype();
            if (originalType != null) {
              canonResultValue=Node.createLiteral(lex,originalType);
            }
          }
 else {
            throw new RuntimeException("String_Node_Str" + resultValue + "String_Node_Str"+ canonResultValue);
          }
        }
      }
      result.add(bindingVar,canonResultValue);
    }
  }
  return result;
}