Program: 23993
Project: 23993
Buggy source:
/** 
 * this is called externally to generate a set of structures to a single ShEx file generally, it will be called with a single structure, or a long list of structures (all of them)
 * @param links HTML link rendering policy
 * @param structures list of structure definitions to render
 * @return ShEx definition of structures
 */
public String generate(HTMLLinkPolicy links,List<StructureDefinition> structures){
  ST shex_def=tmplt(SHEX_TEMPLATE);
  shex_def.add("String_Node_Str",tmplt(HEADER_TEMPLATE).add("String_Node_Str",structures.get(0).getId()).add("String_Node_Str",FHIR).render());
  Collections.sort(structures,new SortById());
  StringBuilder shapeDefinitions=new StringBuilder();
  uniq_structures=new LinkedList<StructureDefinition>();
  uniq_structure_urls=new HashSet<String>();
  for (  StructureDefinition sd : structures) {
    if (!uniq_structure_urls.contains(sd.getUrl())) {
      uniq_structures.add(sd);
      uniq_structure_urls.add(sd.getUrl());
    }
  }
  for (  StructureDefinition sd : uniq_structures) {
    shapeDefinitions.append(genShapeDefinition(sd,true));
  }
  shapeDefinitions.append(emitInnerTypes());
  if (doDatatypes) {
    shapeDefinitions.append("String_Node_Str");
    while (emittedDatatypes.size() < datatypes.size() || emittedInnerTypes.size() < innerTypes.size()) {
      shapeDefinitions.append(emitDataTypes());
      shapeDefinitions.append(emitInnerTypes());
    }
  }
  shapeDefinitions.append("String_Node_Str");
  for (  String r : references)   shapeDefinitions.append("String_Node_Str").append(tmplt(TYPED_REFERENCE_TEMPLATE).add("String_Node_Str",r).render()).append("String_Node_Str");
  shex_def.add("String_Node_Str",shapeDefinitions);
  return shex_def.render();
}

Fixed version (ground truth):
/** 
 * this is called externally to generate a set of structures to a single ShEx file generally, it will be called with a single structure, or a long list of structures (all of them)
 * @param links HTML link rendering policy
 * @param structures list of structure definitions to render
 * @return ShEx definition of structures
 */
public String generate(HTMLLinkPolicy links,List<StructureDefinition> structures){
  ST shex_def=tmplt(SHEX_TEMPLATE);
  String start_cmd=completeModel ? tmplt(START_TEMPLATE).add("String_Node_Str",structures.get(0).getId()).render() : "String_Node_Str";
  shex_def.add("String_Node_Str",tmplt(HEADER_TEMPLATE).add("String_Node_Str",start_cmd).add("String_Node_Str",FHIR).render());
  Collections.sort(structures,new SortById());
  StringBuilder shapeDefinitions=new StringBuilder();
  uniq_structures=new LinkedList<StructureDefinition>();
  uniq_structure_urls=new HashSet<String>();
  for (  StructureDefinition sd : structures) {
    if (!uniq_structure_urls.contains(sd.getUrl())) {
      uniq_structures.add(sd);
      uniq_structure_urls.add(sd.getUrl());
    }
  }
  for (  StructureDefinition sd : uniq_structures) {
    shapeDefinitions.append(genShapeDefinition(sd,true));
  }
  shapeDefinitions.append(emitInnerTypes());
  if (doDatatypes) {
    shapeDefinitions.append("String_Node_Str");
    while (emittedDatatypes.size() < datatypes.size() || emittedInnerTypes.size() < innerTypes.size()) {
      shapeDefinitions.append(emitDataTypes());
      shapeDefinitions.append(emitInnerTypes());
    }
  }
  shapeDefinitions.append("String_Node_Str");
  for (  String r : references)   shapeDefinitions.append("String_Node_Str").append(tmplt(TYPED_REFERENCE_TEMPLATE).add("String_Node_Str",r).render()).append("String_Node_Str");
  shex_def.add("String_Node_Str",shapeDefinitions);
  return shex_def.render();
}