Program: 24044
Project: 24044
Buggy source:
/** 
 * Generate a ShEx element definition
 * @param sd Containing structure definition
 * @param ed Containing element definition
 * @return ShEx definition
 */
private String genElementDefinition(StructureDefinition sd,ElementDefinition ed){
  ST element_def=tmplt(ELEMENT_TEMPLATE);
  String id=ed.hasBase() ? ed.getBase().getPath() : ed.getPath();
  String shortId=id.substring(id.lastIndexOf("String_Node_Str") + 1);
  String card="String_Node_Str".equals(ed.getMax()) ? (ed.getMin() == 0 ? "String_Node_Str" : "String_Node_Str") : "String_Node_Str";
  String defn;
  element_def.add("String_Node_Str",id.charAt(0) == id.toLowerCase().charAt(0) ? shortId : id);
  element_def.add("String_Node_Str",card);
  List<ElementDefinition> children=ProfileUtilities.getChildList(sd,ed);
  if (children.size() > 0) {
    innerTypes.add(new ImmutablePair<StructureDefinition,ElementDefinition>(sd,ed));
    ST anon_link=tmplt(SIMPLE_ELEMENT_TEMPLATE);
    anon_link.add("String_Node_Str",id);
    defn=anon_link.render();
  }
 else   if (ed.getType().size() == 1) {
    defn=genTypeRef(ed.getType().get(0));
  }
 else   if (ed.getContentReference() != null) {
    String typ=id.substring(0,id.indexOf("String_Node_Str") + 1) + ed.getContentReference().substring(1);
    ST defn_ref=tmplt(SIMPLE_ELEMENT_TEMPLATE);
    defn_ref.add("String_Node_Str",typ);
    defn=defn_ref.render();
  }
 else {
    if (id.endsWith("String_Node_Str")) {
      return genChoiceTypes(ed,id,shortId,card);
    }
 else {
      defn=genAlternativeTypes(ed,id,shortId,card);
    }
  }
  element_def.add("String_Node_Str",defn);
  return element_def.render();
}

Fixed version (ground truth):
/** 
 * Generate a ShEx element definition
 * @param sd Containing structure definition
 * @param ed Containing element definition
 * @return ShEx definition
 */
private String genElementDefinition(StructureDefinition sd,ElementDefinition ed){
  ST element_def=tmplt(ELEMENT_TEMPLATE);
  String id=ed.hasBase() ? ed.getBase().getPath() : ed.getPath();
  String shortId=id.substring(id.lastIndexOf("String_Node_Str") + 1);
  String card="String_Node_Str".equals(ed.getMax()) ? (ed.getMin() == 0 ? "String_Node_Str" : "String_Node_Str") : (ed.getMin() == 0 ? "String_Node_Str" : "String_Node_Str");
  String defn;
  element_def.add("String_Node_Str",id.charAt(0) == id.toLowerCase().charAt(0) ? shortId : id);
  element_def.add("String_Node_Str",card);
  List<ElementDefinition> children=ProfileUtilities.getChildList(sd,ed);
  if (children.size() > 0) {
    innerTypes.add(new ImmutablePair<StructureDefinition,ElementDefinition>(sd,ed));
    ST anon_link=tmplt(SIMPLE_ELEMENT_TEMPLATE);
    anon_link.add("String_Node_Str",id);
    defn=anon_link.render();
  }
 else   if (ed.getType().size() == 1) {
    defn=genTypeRef(ed.getType().get(0));
  }
 else   if (ed.getContentReference() != null) {
    String typ=id.substring(0,id.indexOf("String_Node_Str") + 1) + ed.getContentReference().substring(1);
    ST defn_ref=tmplt(SIMPLE_ELEMENT_TEMPLATE);
    defn_ref.add("String_Node_Str",typ);
    defn=defn_ref.render();
  }
 else {
    if (id.endsWith("String_Node_Str")) {
      return genChoiceTypes(ed,id,shortId,card);
    }
 else {
      defn=genAlternativeTypes(ed,id,shortId,card);
    }
  }
  element_def.add("String_Node_Str",defn);
  return element_def.render();
}