Program: 23170
Project: 23170
Buggy source:
private void processTypes(String baseResourceName,FHIRResource baseResource,ElementDefn td,String predicateBase,boolean innerIsBackbone) throws Exception {
  for (  ElementDefn ed : td.getElements()) {
    String predicateName=predicateBase + "String_Node_Str" + (ed.getName().endsWith("String_Node_Str") ? ed.getName().substring(0,ed.getName().length() - 3) : ed.getName());
    FHIRResource predicateResource;
    if (ed.getName().endsWith("String_Node_Str")) {
      predicateResource=fact.fhir_objectProperty(predicateName);
      if (ed.typeCode().equals("String_Node_Str")) {
        Resource targetResource=RDFNamespace.FHIR.resourceRef("String_Node_Str");
        baseResource.restriction(fact.fhir_cardinality_restriction(predicateResource.resource,targetResource,ed.getMinCardinality(),ed.getMaxCardinality()));
        predicateResource.domain(baseResource);
        predicateResource.range(targetResource);
      }
 else {
        List<Resource> typeOpts=new ArrayList<Resource>();
        for (        TypeRef tr : ed.getTypes()) {
          String qualifiedPredicateName=predicateName + Utilities.capitalize(tr.getName());
          Resource targetRes=fact.fhir_class(tr.getName()).resource;
          FHIRResource qualifiedPredicate=fact.fhir_objectProperty(qualifiedPredicateName,predicateResource.resource).domain(baseResource).range(targetRes);
          typeOpts.add(fact.fhir_cardinality_restriction(qualifiedPredicate.resource,targetRes,ed.getMinCardinality(),ed.getMaxCardinality()));
        }
        baseResource.restriction(fact.fhir_union(typeOpts));
      }
    }
 else {
      FHIRResource baseDef;
      if (ed.getTypes().isEmpty()) {
        predicateResource=fact.fhir_objectProperty(predicateName);
        String targetClassName=mapComponentName(baseResourceName,ed.getDeclaredTypeName());
        baseDef=fact.fhir_class(targetClassName,innerIsBackbone ? "String_Node_Str" : "String_Node_Str").addDefinition(ed.getDefinition());
        processTypes(targetClassName,baseDef,ed,predicateName,innerIsBackbone);
      }
 else {
        TypeRef targetType=ed.getTypes().get(0);
        String targetName=targetType.getName();
        if (targetName.startsWith("String_Node_Str")) {
          ElementDefn targetRef=getElementForPath(targetName.substring(1));
          String targetRefName=targetRef.getName();
          String targetClassName=baseResourceName + Character.toUpperCase(targetRefName.charAt(0)) + targetRefName.substring(1);
          baseDef=fact.fhir_class(targetClassName,innerIsBackbone ? "String_Node_Str" : "String_Node_Str").addDefinition(ed.getDefinition()).addTitle(ed.getShortDefn());
          if (!processing.contains(targetRefName)) {
            processing.add(targetRefName);
            processTypes(targetClassName,baseDef,targetRef,predicateName,innerIsBackbone);
            processing.remove(targetRefName);
          }
        }
 else {
          baseDef=fact.fhir_class(targetName);
        }
        if (targetName.equals("String_Node_Str"))         predicateResource=fact.fhir_dataProperty(predicateName);
 else         predicateResource=fact.fhir_objectProperty(predicateName);
      }
      predicateResource.addTitle(ed.getShortDefn()).addDefinition(ed.getDefinition()).domain(baseResource);
      baseResource.restriction(fact.fhir_cardinality_restriction(predicateResource.resource,baseDef.resource,ed.getMinCardinality(),ed.getMaxCardinality()));
      predicateResource.range(baseDef.resource);
      if (!Utilities.noString(ed.getW5()))       predicateResource.addObjectProperty(RDFS.subPropertyOf,RDFNamespace.W5.resourceRef(ed.getW5()));
    }
  }
}

Fixed version (ground truth):
private void processTypes(String baseResourceName,FHIRResource baseResource,ElementDefn td,String predicateBase,boolean innerIsBackbone) throws Exception {
  for (  ElementDefn ed : td.getElements()) {
    String predicateName=predicateBase + "String_Node_Str" + (ed.getName().endsWith("String_Node_Str") ? ed.getName().substring(0,ed.getName().length() - 3) : ed.getName());
    FHIRResource predicateResource;
    if (ed.getName().endsWith("String_Node_Str")) {
      predicateResource=fact.fhir_objectProperty(predicateName);
      if (ed.typeCode().equals("String_Node_Str")) {
        Resource targetResource=RDFNamespace.FHIR.resourceRef("String_Node_Str");
        baseResource.restriction(fact.fhir_cardinality_restriction(predicateResource.resource,targetResource,ed.getMinCardinality(),ed.getMaxCardinality()));
        predicateResource.domain(baseResource);
        predicateResource.range(targetResource);
      }
 else {
        List<Resource> typeOpts=new ArrayList<Resource>();
        for (        TypeRef tr : ed.getTypes()) {
          String trName=tr.getName();
          if (trName.equals("String_Node_Str"))           trName="String_Node_Str";
          String qualifiedPredicateName=predicateName + Utilities.capitalize(trName);
          Resource targetRes=fact.fhir_class(tr.getName()).resource;
          FHIRResource qualifiedPredicate=fact.fhir_objectProperty(qualifiedPredicateName,predicateResource.resource).domain(baseResource).range(targetRes);
          typeOpts.add(fact.fhir_cardinality_restriction(qualifiedPredicate.resource,targetRes,ed.getMinCardinality(),ed.getMaxCardinality()));
        }
        baseResource.restriction(fact.fhir_union(typeOpts));
      }
    }
 else {
      FHIRResource baseDef;
      if (ed.getTypes().isEmpty()) {
        predicateResource=fact.fhir_objectProperty(predicateName);
        String targetClassName=mapComponentName(baseResourceName,ed.getDeclaredTypeName());
        baseDef=fact.fhir_class(targetClassName,innerIsBackbone ? "String_Node_Str" : "String_Node_Str").addDefinition(ed.getDefinition());
        processTypes(targetClassName,baseDef,ed,predicateName,innerIsBackbone);
      }
 else {
        TypeRef targetType=ed.getTypes().get(0);
        String targetName=targetType.getName();
        if (targetName.startsWith("String_Node_Str")) {
          ElementDefn targetRef=getElementForPath(targetName.substring(1));
          String targetRefName=targetRef.getName();
          String targetClassName=baseResourceName + Character.toUpperCase(targetRefName.charAt(0)) + targetRefName.substring(1);
          baseDef=fact.fhir_class(targetClassName,innerIsBackbone ? "String_Node_Str" : "String_Node_Str").addDefinition(ed.getDefinition()).addTitle(ed.getShortDefn());
          if (!processing.contains(targetRefName)) {
            processing.add(targetRefName);
            processTypes(targetClassName,baseDef,targetRef,predicateName,innerIsBackbone);
            processing.remove(targetRefName);
          }
        }
 else {
          baseDef=fact.fhir_class(targetName);
        }
        if (targetName.equals("String_Node_Str"))         predicateResource=fact.fhir_dataProperty(predicateName);
 else         predicateResource=fact.fhir_objectProperty(predicateName);
      }
      predicateResource.addTitle(ed.getShortDefn()).addDefinition(ed.getDefinition()).domain(baseResource);
      baseResource.restriction(fact.fhir_cardinality_restriction(predicateResource.resource,baseDef.resource,ed.getMinCardinality(),ed.getMaxCardinality()));
      predicateResource.range(baseDef.resource);
      if (!Utilities.noString(ed.getW5()))       predicateResource.addObjectProperty(RDFS.subPropertyOf,RDFNamespace.W5.resourceRef(ed.getW5()));
    }
  }
}