Program: 112354
Project: 112354
Buggy source:
private void fillProfile(Structure theStruct,StructureElement theElement,BaseRuntimeElementDefinition<?> def,LinkedList<String> path,BaseRuntimeDeclaredChildDefinition theChild){
  fillBasics(theElement,def,path,theChild);
  String expectedPath=StringUtils.join(path,'.');
  ourLog.info("String_Node_Str",expectedPath);
  if (!expectedPath.equals(def.getName())) {
    theElement.getDefinition().getNameReference().setValue(def.getName());
    return;
  }
  fillExtensions(theStruct,path,def.getExtensionsNonModifier(),"String_Node_Str",false);
  fillExtensions(theStruct,path,def.getExtensionsModifier(),"String_Node_Str",true);
  if (def.getChildType() == ChildTypeEnum.RESOURCE) {
    StructureElement narrative=theStruct.addElement();
    narrative.setName("String_Node_Str");
    narrative.setPath(join(path,'.') + "String_Node_Str");
    narrative.getDefinition().addType().setCode(DataTypeEnum.NARRATIVE);
    narrative.getDefinition().setIsModifier(false);
    narrative.getDefinition().setMin(0);
    narrative.getDefinition().setMax("String_Node_Str");
    StructureElement contained=theStruct.addElement();
    contained.setName("String_Node_Str");
    contained.setPath(join(path,'.') + "String_Node_Str");
    contained.getDefinition().addType().getCode().setValue("String_Node_Str");
    contained.getDefinition().setIsModifier(false);
    contained.getDefinition().setMin(0);
    contained.getDefinition().setMax("String_Node_Str");
  }
  if (def instanceof BaseRuntimeElementCompositeDefinition) {
    BaseRuntimeElementCompositeDefinition<?> cdef=((BaseRuntimeElementCompositeDefinition<?>)def);
    for (    BaseRuntimeChildDefinition nextChild : cdef.getChildren()) {
      if (nextChild instanceof RuntimeChildUndeclaredExtensionDefinition) {
        continue;
      }
      BaseRuntimeDeclaredChildDefinition child=(BaseRuntimeDeclaredChildDefinition)nextChild;
      StructureElement elem=theStruct.addElement();
      fillMinAndMaxAndDefinitions(child,elem);
      if (child instanceof RuntimeChildResourceBlockDefinition) {
        RuntimeResourceBlockDefinition nextDef=(RuntimeResourceBlockDefinition)child.getSingleChildOrThrow();
        fillProfile(theStruct,elem,nextDef,path,child);
      }
 else       if (child instanceof RuntimeChildContainedResources) {
      }
 else       if (child instanceof RuntimeChildDeclaredExtensionDefinition) {
        throw new IllegalStateException("String_Node_Str" + child.getClass().getCanonicalName());
      }
 else       if (child instanceof RuntimeChildCompositeDatatypeDefinition || child instanceof RuntimeChildPrimitiveDatatypeDefinition || child instanceof RuntimeChildChoiceDefinition|| child instanceof RuntimeChildResourceDefinition) {
        Iterator<String> childNamesIter=child.getValidChildNames().iterator();
        String nextName=childNamesIter.next();
        BaseRuntimeElementDefinition<?> nextDef=child.getChildByName(nextName);
        fillBasics(elem,nextDef,path,child);
        fillName(elem,nextDef);
        while (childNamesIter.hasNext()) {
          nextDef=child.getChildByName(childNamesIter.next());
          fillName(elem,nextDef);
        }
        path.pollLast();
      }
 else {
        throw new IllegalStateException("String_Node_Str" + child.getClass().getCanonicalName());
      }
    }
  }
 else {
    throw new IllegalStateException("String_Node_Str" + def.getClass().getCanonicalName());
  }
  path.pollLast();
}

Fixed version (ground truth):
private void fillProfile(Structure theStruct,StructureElement theElement,BaseRuntimeElementDefinition<?> def,LinkedList<String> path,BaseRuntimeDeclaredChildDefinition theChild){
  fillBasics(theElement,def,path,theChild);
  String expectedPath=StringUtils.join(path,'.');
  ourLog.info("String_Node_Str",expectedPath);
  String name=def.getName();
  if (!expectedPath.equals(name)) {
    path.pollLast();
    theElement.getDefinition().getNameReference().setValue(def.getName());
    return;
  }
  fillExtensions(theStruct,path,def.getExtensionsNonModifier(),"String_Node_Str",false);
  fillExtensions(theStruct,path,def.getExtensionsModifier(),"String_Node_Str",true);
  if (def.getChildType() == ChildTypeEnum.RESOURCE) {
    StructureElement narrative=theStruct.addElement();
    narrative.setName("String_Node_Str");
    narrative.setPath(join(path,'.') + "String_Node_Str");
    narrative.getDefinition().addType().setCode(DataTypeEnum.NARRATIVE);
    narrative.getDefinition().setIsModifier(false);
    narrative.getDefinition().setMin(0);
    narrative.getDefinition().setMax("String_Node_Str");
    StructureElement contained=theStruct.addElement();
    contained.setName("String_Node_Str");
    contained.setPath(join(path,'.') + "String_Node_Str");
    contained.getDefinition().addType().getCode().setValue("String_Node_Str");
    contained.getDefinition().setIsModifier(false);
    contained.getDefinition().setMin(0);
    contained.getDefinition().setMax("String_Node_Str");
  }
  if (def instanceof BaseRuntimeElementCompositeDefinition) {
    BaseRuntimeElementCompositeDefinition<?> cdef=((BaseRuntimeElementCompositeDefinition<?>)def);
    for (    BaseRuntimeChildDefinition nextChild : cdef.getChildren()) {
      if (nextChild instanceof RuntimeChildUndeclaredExtensionDefinition) {
        continue;
      }
      BaseRuntimeDeclaredChildDefinition child=(BaseRuntimeDeclaredChildDefinition)nextChild;
      StructureElement elem=theStruct.addElement();
      fillMinAndMaxAndDefinitions(child,elem);
      if (child instanceof RuntimeChildResourceBlockDefinition) {
        RuntimeResourceBlockDefinition nextDef=(RuntimeResourceBlockDefinition)child.getSingleChildOrThrow();
        fillProfile(theStruct,elem,nextDef,path,child);
      }
 else       if (child instanceof RuntimeChildContainedResources) {
      }
 else       if (child instanceof RuntimeChildDeclaredExtensionDefinition) {
        throw new IllegalStateException("String_Node_Str" + child.getClass().getCanonicalName());
      }
 else       if (child instanceof RuntimeChildCompositeDatatypeDefinition || child instanceof RuntimeChildPrimitiveDatatypeDefinition || child instanceof RuntimeChildChoiceDefinition|| child instanceof RuntimeChildResourceDefinition) {
        Iterator<String> childNamesIter=child.getValidChildNames().iterator();
        String nextName=childNamesIter.next();
        BaseRuntimeElementDefinition<?> nextDef=child.getChildByName(nextName);
        fillBasics(elem,nextDef,path,child);
        fillName(elem,nextDef);
        while (childNamesIter.hasNext()) {
          nextDef=child.getChildByName(childNamesIter.next());
          fillName(elem,nextDef);
        }
        path.pollLast();
      }
 else {
        throw new IllegalStateException("String_Node_Str" + child.getClass().getCanonicalName());
      }
    }
  }
 else {
    throw new IllegalStateException("String_Node_Str" + def.getClass().getCanonicalName());
  }
  path.pollLast();
}