Program: 9864
Project: 9864
Buggy source:
/** 
 * Creates a mapping from a view instance: - For every binding variable, that maps to multiple things (contants + variables), we need to equate all these things being mapped to Schematically, we need to transform the binding to variable definitions from the original structure (query view definition) q    v   d / dx1 ?x /    \ dxn ?s   \    / dy1 ?y \ dyn to conceptually a CNF: (dx1 = dy1 OR ... OR dx1 = dyn) AND ... AND (dxn = dy1 OR ... OR dxn = dyn) However, as equals is transitive and symmetric, it is sufficient to just pick the set of definitions for one view variable.
 * @param generator
 * @param viewInstance
 * @return
 */
public Mapping createMapping(ViewInstance viewInstance){
  Set<Var> queryVars=viewInstance.getBinding().getQueryVars();
  Multimap<Var,RestrictedExpr> newVarDefMap=HashMultimap.create();
  List<SqlExpr> ands=null;
  for (  Var queryVar : queryVars) {
    Node constant=viewInstance.getBinding().getConstant(queryVar);
    if (constant != null) {
      NodeValue nv=NodeValue.makeNode(constant);
      newVarDefMap.put(queryVar,new RestrictedExpr(nv));
      continue;
    }
    VarDefKey ors=joinDefinitionsOnEquals(queryVar,viewInstance,exprTransformer,sqlTranslator);
    if (ors == null) {
      return createEmptyMapping(viewInstance);
    }
    newVarDefMap.putAll(queryVar,ors.definitionExprs);
    SqlExpr or=SqlExprUtils.orifyBalanced(ors.constraintExpr);
    if (or == null || or.equals(S_Constant.TRUE)) {
      continue;
    }
    if (ands == null) {
      ands=new ArrayList<SqlExpr>();
    }
    if (or.equals(S_Constant.FALSE)) {
      continue;
    }
 else {
      ands.add(or);
    }
  }
  VarDefinition varDefinition=new VarDefinition(newVarDefMap);
  Mapping result=null;
  SqlOp op=viewInstance.getViewDefinition().getMapping().getSqlOp();
  if (ands == null) {
    result=new Mapping(varDefinition,op);
  }
 else   if (ands.isEmpty()) {
    result=createEmptyMapping(viewInstance);
  }
 else {
    SqlOp filterOp=SqlOpFilter.create(op,ands);
    result=new Mapping(varDefinition,filterOp);
  }
  return result;
}

Fixed version (ground truth):
/** 
 * Creates a mapping from a view instance: - For every binding variable, that maps to multiple things (contants + variables), we need to equate all these things being mapped to Schematically, we need to transform the binding to variable definitions from the original structure (query view definition) q    v   d / dx1 ?x /    \ dxn ?s   \    / dy1 ?y \ dyn to conceptually a CNF: (dx1 = dy1 OR ... OR dx1 = dyn) AND ... AND (dxn = dy1 OR ... OR dxn = dyn) However, as equals is transitive and symmetric, it is sufficient to just pick the set of definitions for one view variable.
 * @param generator
 * @param viewInstance
 * @return
 */
public Mapping createMapping(ViewInstance viewInstance){
  Set<Var> queryVars=viewInstance.getBinding().getQueryVars();
  Multimap<Var,RestrictedExpr> newVarDefMap=HashMultimap.create();
  List<SqlExpr> ands=null;
  for (  Var queryVar : queryVars) {
    Node constant=viewInstance.getBinding().getConstant(queryVar);
    if (constant != null) {
      NodeValue nv=NodeValue.makeNode(constant);
      newVarDefMap.put(queryVar,new RestrictedExpr(nv));
      continue;
    }
    VarDefKey ors=joinDefinitionsOnEquals(queryVar,viewInstance,exprTransformer,sqlTranslator);
    if (ors == null) {
      return createEmptyMapping(viewInstance);
    }
    newVarDefMap.putAll(queryVar,ors.definitionExprs);
    SqlExpr or=SqlExprUtils.orifyBalanced(ors.constraintExpr);
    if (or == null || or.equals(S_Constant.TRUE)) {
      continue;
    }
    if (ands == null) {
      ands=new ArrayList<SqlExpr>();
    }
    if (or.equals(S_Constant.FALSE)) {
      continue;
    }
 else {
      ands.add(or);
    }
  }
  VarDefinition tmpVarDefinition=new VarDefinition(newVarDefMap);
  VarDefinition varDefinition=tmpVarDefinition.copyExpandConstants();
  Mapping result=null;
  SqlOp op=viewInstance.getViewDefinition().getMapping().getSqlOp();
  if (ands == null) {
    result=new Mapping(varDefinition,op);
  }
 else   if (ands.isEmpty()) {
    result=createEmptyMapping(viewInstance);
  }
 else {
    SqlOp filterOp=SqlOpFilter.create(op,ands);
    result=new Mapping(varDefinition,filterOp);
  }
  return result;
}