Program: 22957
Project: 22957
Buggy source:
private List<Variables> processSource(String ruleId,TransformContext context,Variables vars,StructureMapGroupRuleSourceComponent src,String pathForErrors) throws FHIRException {
  List<Base> items;
  if (src.getContext().equals("String_Node_Str")) {
    ExpressionNode expr=(ExpressionNode)src.getUserData(MAP_SEARCH_EXPRESSION);
    if (expr == null) {
      expr=fpe.parse(src.getElement());
      src.setUserData(MAP_SEARCH_EXPRESSION,expr);
    }
    String search=fpe.evaluateToString(vars,null,new StringType(),expr);
    items=services.performSearch(context.appInfo,search);
  }
 else {
    items=new ArrayList<Base>();
    Base b=vars.get(VariableMode.INPUT,src.getContext());
    if (b == null)     throw new FHIRException("String_Node_Str" + src.getContext() + "String_Node_Str"+ pathForErrors+ "String_Node_Str"+ ruleId+ "String_Node_Str"+ vars.summary()+ "String_Node_Str");
    if (!src.hasElement())     items.add(b);
 else {
      getChildrenByName(b,src.getElement(),items);
      if (items.size() == 0 && src.hasDefaultValue())       items.add(src.getDefaultValue());
    }
  }
  if (src.hasType()) {
    List<Base> remove=new ArrayList<Base>();
    for (    Base item : items) {
      if (item != null && !isType(item,src.getType())) {
        remove.add(item);
      }
    }
    items.removeAll(remove);
  }
  if (src.hasCondition()) {
    ExpressionNode expr=(ExpressionNode)src.getUserData(MAP_WHERE_EXPRESSION);
    if (expr == null) {
      expr=fpe.parse(src.getCondition());
      src.setUserData(MAP_WHERE_EXPRESSION,expr);
    }
    List<Base> remove=new ArrayList<Base>();
    for (    Base item : items) {
      if (!fpe.evaluateToBoolean(vars,null,item,expr))       remove.add(item);
    }
    items.removeAll(remove);
  }
  if (src.hasCheck()) {
    ExpressionNode expr=(ExpressionNode)src.getUserData(MAP_WHERE_CHECK);
    if (expr == null) {
      expr=fpe.parse(src.getCheck());
      src.setUserData(MAP_WHERE_CHECK,expr);
    }
    List<Base> remove=new ArrayList<Base>();
    for (    Base item : items) {
      if (!fpe.evaluateToBoolean(vars,null,item,expr))       throw new FHIRException("String_Node_Str" + ruleId + "String_Node_Str");
    }
  }
  if (src.hasLogMessage()) {
    ExpressionNode expr=(ExpressionNode)src.getUserData(MAP_WHERE_LOG);
    if (expr == null) {
      expr=fpe.parse(src.getCheck());
      src.setUserData(MAP_WHERE_LOG,expr);
    }
    CommaSeparatedStringBuilder b=new CommaSeparatedStringBuilder();
    for (    Base item : items)     b.append(fpe.evaluateToString(vars,null,item,expr));
    if (b.length() > 0)     services.log(b.toString());
  }
  if (src.hasListMode() && !items.isEmpty()) {
switch (src.getListMode()) {
case FIRST:
      Base bt=items.get(0);
    items.clear();
  items.add(bt);
break;
case NOTFIRST:
if (items.size() > 0) items.remove(0);
break;
case LAST:
bt=items.get(items.size() - 1);
items.clear();
items.add(bt);
break;
case NOTLAST:
if (items.size() > 0) items.remove(items.size() - 1);
break;
case ONLYONE:
if (items.size() > 1) throw new FHIRException("String_Node_Str" + ruleId + "String_Node_Str");
break;
case NULL:
}
}
List<Variables> result=new ArrayList<Variables>();
for (Base r : items) {
Variables v=vars.copy();
if (src.hasVariable()) v.add(VariableMode.INPUT,src.getVariable(),r);
result.add(v);
}
return result;
}

Fixed version (ground truth):
private List<Variables> processSource(String ruleId,TransformContext context,Variables vars,StructureMapGroupRuleSourceComponent src,String pathForErrors) throws FHIRException {
  List<Base> items;
  if (src.getContext().equals("String_Node_Str")) {
    ExpressionNode expr=(ExpressionNode)src.getUserData(MAP_SEARCH_EXPRESSION);
    if (expr == null) {
      expr=fpe.parse(src.getElement());
      src.setUserData(MAP_SEARCH_EXPRESSION,expr);
    }
    String search=fpe.evaluateToString(vars,null,new StringType(),expr);
    items=services.performSearch(context.appInfo,search);
  }
 else {
    items=new ArrayList<Base>();
    Base b=vars.get(VariableMode.INPUT,src.getContext());
    if (b == null)     throw new FHIRException("String_Node_Str" + src.getContext() + "String_Node_Str"+ pathForErrors+ "String_Node_Str"+ ruleId+ "String_Node_Str"+ vars.summary()+ "String_Node_Str");
    if (!src.hasElement())     items.add(b);
 else {
      getChildrenByName(b,src.getElement(),items);
      if (items.size() == 0 && src.hasDefaultValue())       items.add(src.getDefaultValue());
    }
  }
  if (src.hasType()) {
    List<Base> remove=new ArrayList<Base>();
    for (    Base item : items) {
      if (item != null && !isType(item,src.getType())) {
        remove.add(item);
      }
    }
    items.removeAll(remove);
  }
  if (src.hasCondition()) {
    ExpressionNode expr=(ExpressionNode)src.getUserData(MAP_WHERE_EXPRESSION);
    if (expr == null) {
      expr=fpe.parse(src.getCondition());
      src.setUserData(MAP_WHERE_EXPRESSION,expr);
    }
    List<Base> remove=new ArrayList<Base>();
    for (    Base item : items) {
      if (!fpe.evaluateToBoolean(vars,null,item,expr))       remove.add(item);
    }
    items.removeAll(remove);
  }
  if (src.hasCheck()) {
    ExpressionNode expr=(ExpressionNode)src.getUserData(MAP_WHERE_CHECK);
    if (expr == null) {
      expr=fpe.parse(src.getCheck());
      src.setUserData(MAP_WHERE_CHECK,expr);
    }
    List<Base> remove=new ArrayList<Base>();
    for (    Base item : items) {
      if (!fpe.evaluateToBoolean(vars,null,item,expr))       throw new FHIRException("String_Node_Str" + ruleId + "String_Node_Str");
    }
  }
  if (src.hasLogMessage()) {
    ExpressionNode expr=(ExpressionNode)src.getUserData(MAP_WHERE_LOG);
    if (expr == null) {
      expr=fpe.parse(src.getLogMessage());
      src.setUserData(MAP_WHERE_LOG,expr);
    }
    CommaSeparatedStringBuilder b=new CommaSeparatedStringBuilder();
    for (    Base item : items)     b.appendIfNotNull(fpe.evaluateToString(vars,null,item,expr));
    if (b.length() > 0)     services.log(b.toString());
  }
  if (src.hasListMode() && !items.isEmpty()) {
switch (src.getListMode()) {
case FIRST:
      Base bt=items.get(0);
    items.clear();
  items.add(bt);
break;
case NOTFIRST:
if (items.size() > 0) items.remove(0);
break;
case LAST:
bt=items.get(items.size() - 1);
items.clear();
items.add(bt);
break;
case NOTLAST:
if (items.size() > 0) items.remove(items.size() - 1);
break;
case ONLYONE:
if (items.size() > 1) throw new FHIRException("String_Node_Str" + ruleId + "String_Node_Str");
break;
case NULL:
}
}
List<Variables> result=new ArrayList<Variables>();
for (Base r : items) {
Variables v=vars.copy();
if (src.hasVariable()) v.add(VariableMode.INPUT,src.getVariable(),r);
result.add(v);
}
return result;
}