Program: 23119
Project: 23119
Buggy source:
/** 
 * @param trimDifferential
 * @throws DefinitionException , FHIRException 
 * @throws Exception
 */
private ElementDefinition processPaths(String indent,StructureDefinitionSnapshotComponent result,StructureDefinitionSnapshotComponent base,StructureDefinitionDifferentialComponent differential,int baseCursor,int diffCursor,int baseLimit,int diffLimit,String url,String profileName,String contextPathSrc,String contextPathDst,boolean trimDifferential,String contextName,String resultPathBase,boolean slicingDone,ElementDefinition redirector) throws DefinitionException, FHIRException {
  if (DEBUG)   System.out.println(indent + "String_Node_Str" + resultPathBase+ "String_Node_Str"+ baseCursor+ "String_Node_Str"+ baseLimit+ "String_Node_Str"+ diffCursor+ "String_Node_Str"+ diffLimit+ "String_Node_Str"+ slicingDone+ "String_Node_Str");
  ElementDefinition res=null;
  while (baseCursor <= baseLimit) {
    ElementDefinition currentBase=base.getElement().get(baseCursor);
    String cpath=fixedPathSource(contextPathSrc,currentBase.getPath(),redirector);
    if (DEBUG)     System.out.println(indent + "String_Node_Str" + cpath+ "String_Node_Str"+ baseCursor+ "String_Node_Str"+ baseLimit+ "String_Node_Str"+ diffCursor+ "String_Node_Str"+ diffLimit+ "String_Node_Str"+ slicingDone+ "String_Node_Str");
    List<ElementDefinition> diffMatches=getDiffMatches(differential,cpath,diffCursor,diffLimit,profileName,url);
    if (!currentBase.hasSlicing()) {
      if (diffMatches.isEmpty()) {
        ElementDefinition outcome=updateURLs(url,currentBase.copy());
        outcome.setPath(fixedPathDest(contextPathDst,outcome.getPath(),redirector));
        updateFromBase(outcome,currentBase);
        markDerived(outcome);
        if (resultPathBase == null)         resultPathBase=outcome.getPath();
 else         if (!outcome.getPath().startsWith(resultPathBase))         throw new DefinitionException("String_Node_Str");
        result.getElement().add(outcome);
        if (hasInnerDiffMatches(differential,cpath,diffCursor,diffLimit,base.getElement())) {
          if (outcome.getType().size() > 1) {
            for (            TypeRefComponent t : outcome.getType()) {
              if (!t.getCode().equals("String_Node_Str"))               throw new DefinitionException(diffMatches.get(0).getPath() + "String_Node_Str" + differential.getElement().get(diffCursor).getPath()+ "String_Node_Str"+ typeCode(outcome.getType())+ "String_Node_Str"+ profileName);
            }
          }
          StructureDefinition dt=getProfileForDataType(outcome.getType().get(0));
          if (dt == null)           throw new DefinitionException(cpath + "String_Node_Str" + typeCode(outcome.getType())+ "String_Node_Str"+ profileName+ "String_Node_Str");
          contextName=dt.getUrl();
          int start=diffCursor;
          while (differential.getElement().size() > diffCursor && pathStartsWith(differential.getElement().get(diffCursor).getPath(),cpath + "String_Node_Str"))           diffCursor++;
          processPaths(indent + "String_Node_Str",result,dt.getSnapshot(),differential,1,start,dt.getSnapshot().getElement().size() - 1,diffCursor - 1,url,profileName,cpath,outcome.getPath(),trimDifferential,contextName,resultPathBase,false,null);
        }
        baseCursor++;
      }
 else       if (diffMatches.size() == 1 && (slicingDone || !(diffMatches.get(0).hasSlicing() || (isExtension(diffMatches.get(0)) && diffMatches.get(0).hasSliceName())))) {
        ElementDefinition template=null;
        if (diffMatches.get(0).hasType() && diffMatches.get(0).getType().size() == 1 && diffMatches.get(0).getType().get(0).hasProfile() && !diffMatches.get(0).getType().get(0).getCode().equals("String_Node_Str")) {
          String p=diffMatches.get(0).getType().get(0).getProfile();
          StructureDefinition sd=context.fetchResource(StructureDefinition.class,p);
          if (sd != null) {
            if (!sd.hasSnapshot()) {
              StructureDefinition sdb=context.fetchResource(StructureDefinition.class,sd.getBaseDefinition());
              if (sdb == null)               throw new DefinitionException("String_Node_Str" + sd.getBaseDefinition());
              generateSnapshot(sdb,sd,sd.getUrl(),sd.getName());
            }
            template=sd.getSnapshot().getElement().get(0).copy().setPath(currentBase.getPath());
            template.setSliceName(null);
            if (!diffMatches.get(0).getType().get(0).getCode().equals("String_Node_Str")) {
              template.setMin(currentBase.getMin());
              template.setMax(currentBase.getMax());
            }
          }
        }
        if (template == null)         template=currentBase.copy();
 else         template=overWriteWithCurrent(template,currentBase);
        ElementDefinition outcome=updateURLs(url,template);
        outcome.setPath(fixedPathDest(contextPathDst,outcome.getPath(),redirector));
        res=outcome;
        updateFromBase(outcome,currentBase);
        if (diffMatches.get(0).hasSliceName())         outcome.setSliceName(diffMatches.get(0).getSliceName());
        outcome.setSlicing(null);
        updateFromDefinition(outcome,diffMatches.get(0),profileName,trimDifferential,url);
        if (outcome.getPath().endsWith("String_Node_Str") && outcome.getType().size() == 1 && !outcome.getType().get(0).getCode().equals("String_Node_Str"))         outcome.setPath(outcome.getPath().substring(0,outcome.getPath().length() - 3) + Utilities.capitalize(outcome.getType().get(0).getCode()));
        if (resultPathBase == null)         resultPathBase=outcome.getPath();
 else         if (!outcome.getPath().startsWith(resultPathBase))         throw new DefinitionException("String_Node_Str");
        result.getElement().add(outcome);
        baseCursor++;
        diffCursor=differential.getElement().indexOf(diffMatches.get(0)) + 1;
        if (differential.getElement().size() > diffCursor && outcome.getPath().contains("String_Node_Str") && (isDataType(outcome.getType()) || outcome.hasContentReference())) {
          if (pathStartsWith(differential.getElement().get(diffCursor).getPath(),diffMatches.get(0).getPath() + "String_Node_Str") && !baseWalksInto(base.getElement(),baseCursor)) {
            if (outcome.getType().size() > 1) {
              if (outcome.getPath().endsWith("String_Node_Str") && !diffMatches.get(0).getPath().endsWith("String_Node_Str")) {
                String en=tail(outcome.getPath());
                String tn=tail(diffMatches.get(0).getPath());
                String t=tn.substring(en.length() - 3);
                if (isPrimitive(Utilities.uncapitalize(t)))                 t=Utilities.uncapitalize(t);
                List<TypeRefComponent> ntr=getByTypeName(outcome.getType(),t);
                if (ntr.isEmpty())                 ntr.add(new TypeRefComponent().setCode(t));
                outcome.getType().clear();
                outcome.getType().addAll(ntr);
              }
              if (outcome.getType().size() > 1)               for (              TypeRefComponent t : outcome.getType()) {
                if (!t.getCode().equals("String_Node_Str"))                 throw new DefinitionException(diffMatches.get(0).getPath() + "String_Node_Str" + differential.getElement().get(diffCursor).getPath()+ "String_Node_Str"+ typeCode(outcome.getType())+ "String_Node_Str"+ profileName);
              }
            }
            int start=diffCursor;
            while (differential.getElement().size() > diffCursor && pathStartsWith(differential.getElement().get(diffCursor).getPath(),diffMatches.get(0).getPath() + "String_Node_Str"))             diffCursor++;
            if (outcome.hasContentReference()) {
              ElementDefinition tgt=getElementById(base.getElement(),outcome.getContentReference());
              if (tgt == null)               throw new DefinitionException("String_Node_Str" + outcome.getContentReference());
              replaceFromContentReference(outcome,tgt);
              int nbc=base.getElement().indexOf(tgt) + 1;
              int nbl=nbc;
              while (nbl < base.getElement().size() && base.getElement().get(nbl).getPath().startsWith(tgt.getPath() + "String_Node_Str"))               nbl++;
              processPaths(indent + "String_Node_Str",result,base,differential,nbc,start - 1,nbl - 1,diffCursor - 1,url,profileName,tgt.getPath(),diffMatches.get(0).getPath(),trimDifferential,contextName,resultPathBase,false,outcome);
            }
 else {
              StructureDefinition dt=getProfileForDataType(outcome.getType().get(0));
              if (dt == null)               throw new DefinitionException(diffMatches.get(0).getPath() + "String_Node_Str" + differential.getElement().get(diffCursor).getPath()+ "String_Node_Str"+ typeCode(outcome.getType())+ "String_Node_Str"+ profileName+ "String_Node_Str");
              contextName=dt.getUrl();
              processPaths(indent + "String_Node_Str",result,dt.getSnapshot(),differential,1,start,dt.getSnapshot().getElement().size() - 1,diffCursor - 1,url,profileName + pathTail(diffMatches,0),diffMatches.get(0).getPath(),outcome.getPath(),trimDifferential,contextName,resultPathBase,false,null);
            }
          }
        }
      }
 else {
        if (!unbounded(currentBase) && !isSlicedToOneOnly(diffMatches.get(0)))         throw new DefinitionException("String_Node_Str" + currentBase.getPath() + "String_Node_Str"+ currentBase.getSliceName()+ "String_Node_Str"+ contextName+ "String_Node_Str"+ url);
        if (!diffMatches.get(0).hasSlicing() && !isExtension(currentBase))         throw new DefinitionException("String_Node_Str" + currentBase.getPath() + "String_Node_Str"+ url);
        int start=0;
        int nbl=findEndOfElement(base,baseCursor);
        if (diffMatches.size() > 1 && diffMatches.get(0).hasSlicing() && (nbl > baseCursor || differential.getElement().indexOf(diffMatches.get(1)) > differential.getElement().indexOf(diffMatches.get(0)) + 1)) {
          int ndc=differential.getElement().indexOf(diffMatches.get(0));
          int ndl=findEndOfElement(differential,ndc);
          processPaths(indent + "String_Node_Str",result,base,differential,baseCursor,ndc,nbl,ndl,url,profileName + pathTail(diffMatches,0),contextPathSrc,contextPathDst,trimDifferential,contextName,resultPathBase,true,null).setSlicing(diffMatches.get(0).getSlicing());
          start++;
        }
 else {
          ElementDefinition outcome=updateURLs(url,currentBase.copy());
          outcome.setPath(fixedPathDest(contextPathDst,outcome.getPath(),redirector));
          updateFromBase(outcome,currentBase);
          if (!diffMatches.get(0).hasSlicing())           outcome.setSlicing(makeExtensionSlicing());
 else           outcome.setSlicing(diffMatches.get(0).getSlicing().copy());
          if (!outcome.getPath().startsWith(resultPathBase))           throw new DefinitionException("String_Node_Str");
          result.getElement().add(outcome);
          if (!diffMatches.get(0).hasSliceName()) {
            updateFromDefinition(outcome,diffMatches.get(0),profileName,trimDifferential,url);
            if (!outcome.hasContentReference() && !outcome.hasType()) {
              throw new DefinitionException("String_Node_Str");
            }
            start++;
          }
 else           checkExtensionDoco(outcome);
        }
        int ndc=diffCursor;
        int ndl=diffCursor;
        for (int i=start; i < diffMatches.size(); i++) {
          ndc=differential.getElement().indexOf(diffMatches.get(i));
          ndl=findEndOfElement(differential,ndc);
          processPaths(indent + "String_Node_Str",result,base,differential,baseCursor,ndc,nbl,ndl,url,profileName + pathTail(diffMatches,i),contextPathSrc,contextPathDst,trimDifferential,contextName,resultPathBase,true,null);
        }
        baseCursor=nbl + 1;
        diffCursor=ndl + 1;
      }
    }
 else {
      String path=currentBase.getPath();
      ElementDefinition original=currentBase;
      if (diffMatches.isEmpty()) {
        while (baseCursor < base.getElement().size() && base.getElement().get(baseCursor).getPath().startsWith(path)) {
          ElementDefinition outcome=updateURLs(url,base.getElement().get(baseCursor).copy());
          outcome.setPath(fixedPathDest(contextPathDst,outcome.getPath(),redirector));
          if (!outcome.getPath().startsWith(resultPathBase))           throw new DefinitionException("String_Node_Str" + profileName + "String_Node_Str"+ outcome.getPath()+ "String_Node_Str"+ resultPathBase);
          result.getElement().add(outcome);
          baseCursor++;
        }
      }
 else {
        boolean closed=currentBase.getSlicing().getRules() == SlicingRules.CLOSED;
        int diffpos=0;
        boolean isExtension=cpath.endsWith("String_Node_Str") || cpath.endsWith("String_Node_Str");
        if (diffMatches.get(0).hasSlicing()) {
          ElementDefinitionSlicingComponent dSlice=diffMatches.get(0).getSlicing();
          ElementDefinitionSlicingComponent bSlice=currentBase.getSlicing();
          if (dSlice.hasOrderedElement() && bSlice.hasOrderedElement() && !orderMatches(dSlice.getOrderedElement(),bSlice.getOrderedElement()))           throw new DefinitionException("String_Node_Str" + summarizeSlicing(dSlice) + "String_Node_Str"+ summarizeSlicing(bSlice)+ "String_Node_Str"+ path+ "String_Node_Str"+ contextName+ "String_Node_Str");
          if (!discriminatorMatches(dSlice.getDiscriminator(),bSlice.getDiscriminator()))           throw new DefinitionException("String_Node_Str" + summarizeSlicing(dSlice) + "String_Node_Str"+ summarizeSlicing(bSlice)+ "String_Node_Str"+ path+ "String_Node_Str"+ contextName+ "String_Node_Str");
          if (!ruleMatches(dSlice.getRules(),bSlice.getRules()))           throw new DefinitionException("String_Node_Str" + summarizeSlicing(dSlice) + "String_Node_Str"+ summarizeSlicing(bSlice)+ "String_Node_Str"+ path+ "String_Node_Str"+ contextName+ "String_Node_Str");
        }
        ElementDefinition outcome=updateURLs(url,currentBase.copy());
        outcome.setPath(fixedPathDest(contextPathDst,outcome.getPath(),redirector));
        updateFromBase(outcome,currentBase);
        if (diffMatches.get(0).hasSlicing() || !diffMatches.get(0).hasSliceName()) {
          updateFromSlicing(outcome.getSlicing(),diffMatches.get(0).getSlicing());
          updateFromDefinition(outcome,diffMatches.get(0),profileName,closed,url);
        }
 else         if (!diffMatches.get(0).hasSliceName())         diffMatches.get(0).setUserData(GENERATED_IN_SNAPSHOT,true);
        result.getElement().add(outcome);
        if (!diffMatches.get(0).hasSliceName()) {
          diffpos++;
        }
        if (diffMatches.size() > 1 && diffMatches.get(0).hasSlicing() && differential.getElement().indexOf(diffMatches.get(1)) > differential.getElement().indexOf(diffMatches.get(0)) + 1) {
          int nbl=findEndOfElement(base,baseCursor);
          int ndc=differential.getElement().indexOf(diffMatches.get(0));
          int ndl=findEndOfElement(differential,ndc);
          processPaths(indent + "String_Node_Str",result,base,differential,baseCursor + 1,ndc,nbl,ndl,url,profileName + pathTail(diffMatches,0),contextPathSrc,contextPathDst,trimDifferential,contextName,resultPathBase,true,null);
        }
        List<ElementDefinition> baseMatches=getSiblings(base.getElement(),currentBase);
        for (        ElementDefinition baseItem : baseMatches) {
          baseCursor=base.getElement().indexOf(baseItem);
          outcome=updateURLs(url,baseItem.copy());
          updateFromBase(outcome,currentBase);
          outcome.setPath(fixedPathDest(contextPathDst,outcome.getPath(),redirector));
          outcome.setSlicing(null);
          if (!outcome.getPath().startsWith(resultPathBase))           throw new DefinitionException("String_Node_Str");
          if (diffpos < diffMatches.size() && diffMatches.get(diffpos).getSliceName().equals(outcome.getSliceName())) {
            int nbl=findEndOfElement(base,baseCursor);
            int ndc=differential.getElement().indexOf(diffMatches.get(diffpos));
            int ndl=findEndOfElement(differential,ndc);
            processPaths(indent + "String_Node_Str",result,base,differential,baseCursor,ndc,nbl,ndl,url,profileName + pathTail(diffMatches,diffpos),contextPathSrc,contextPathDst,closed,contextName,resultPathBase,true,null);
            baseCursor=nbl;
            diffCursor=ndl + 1;
            diffpos++;
          }
 else {
            result.getElement().add(outcome);
            baseCursor++;
            while (baseCursor < base.getElement().size() && base.getElement().get(baseCursor).getPath().startsWith(path) && !base.getElement().get(baseCursor).getPath().equals(path)) {
              outcome=updateURLs(url,base.getElement().get(baseCursor).copy());
              outcome.setPath(fixedPathDest(contextPathDst,outcome.getPath(),redirector));
              if (!outcome.getPath().startsWith(resultPathBase))               throw new DefinitionException("String_Node_Str");
              result.getElement().add(outcome);
              baseCursor++;
            }
            baseCursor--;
          }
        }
        if (closed && diffpos < diffMatches.size())         throw new DefinitionException("String_Node_Str" + profileName + "String_Node_Str"+ path+ "String_Node_Str"+ cpath+ "String_Node_Str");
        if (diffpos == diffMatches.size()) {
        }
 else {
          while (diffpos < diffMatches.size()) {
            ElementDefinition diffItem=diffMatches.get(diffpos);
            for (            ElementDefinition baseItem : baseMatches)             if (baseItem.getSliceName().equals(diffItem.getSliceName()))             throw new DefinitionException("String_Node_Str");
            outcome=updateURLs(url,currentBase.copy());
            outcome.setPath(fixedPathDest(contextPathDst,outcome.getPath(),redirector));
            updateFromBase(outcome,currentBase);
            outcome.setSlicing(null);
            if (!outcome.getPath().startsWith(resultPathBase))             throw new DefinitionException("String_Node_Str");
            result.getElement().add(outcome);
            updateFromDefinition(outcome,diffItem,profileName,trimDifferential,url);
            diffCursor=differential.getElement().indexOf(diffItem) + 1;
            if (!outcome.getType().isEmpty() && (differential.getElement().size() > diffCursor) && outcome.getPath().contains("String_Node_Str")&& isDataType(outcome.getType())) {
              if (!baseWalksInto(base.getElement(),baseCursor)) {
                if (differential.getElement().size() > diffCursor && pathStartsWith(differential.getElement().get(diffCursor).getPath(),diffMatches.get(0).getPath() + "String_Node_Str")) {
                  if (outcome.getType().size() > 1)                   for (                  TypeRefComponent t : outcome.getType()) {
                    if (!t.getCode().equals("String_Node_Str"))                     throw new DefinitionException(diffMatches.get(0).getPath() + "String_Node_Str" + differential.getElement().get(diffCursor).getPath()+ "String_Node_Str"+ typeCode(outcome.getType())+ "String_Node_Str"+ profileName);
                  }
                  TypeRefComponent t=outcome.getType().get(0);
                  StructureDefinition dt=getProfileForDataType(outcome.getType().get(0));
                  if (dt == null)                   throw new DefinitionException(diffMatches.get(0).getPath() + "String_Node_Str" + differential.getElement().get(diffCursor).getPath()+ "String_Node_Str"+ typeCode(outcome.getType())+ "String_Node_Str"+ profileName+ "String_Node_Str");
                  contextName=dt.getUrl();
                  int start=diffCursor;
                  while (differential.getElement().size() > diffCursor && pathStartsWith(differential.getElement().get(diffCursor).getPath(),diffMatches.get(0).getPath() + "String_Node_Str"))                   diffCursor++;
                  processPaths(indent + "String_Node_Str",result,dt.getSnapshot(),differential,1,start - 1,dt.getSnapshot().getElement().size() - 1,diffCursor - 1,url,profileName + pathTail(diffMatches,0),diffMatches.get(0).getPath(),outcome.getPath(),trimDifferential,contextName,resultPathBase,false,null);
                }
 else                 if (outcome.getType().get(0).getCode().equals("String_Node_Str")) {
                  StructureDefinition dt=getProfileForDataType(outcome.getType().get(0));
                  for (                  ElementDefinition extEd : dt.getSnapshot().getElement()) {
                    if (extEd.getPath().contains("String_Node_Str")) {
                      ElementDefinition extUrlEd=updateURLs(url,extEd.copy());
                      extUrlEd.setPath(fixedPathDest(outcome.getPath(),extUrlEd.getPath(),null));
                      markDerived(extUrlEd);
                      result.getElement().add(extUrlEd);
                    }
                  }
                }
              }
            }
            diffpos++;
          }
        }
        baseCursor++;
      }
    }
  }
  int i=0;
  for (  ElementDefinition e : result.getElement()) {
    i++;
    if (e.hasMinElement() && e.getMinElement().getValue() == null)     throw new Error("String_Node_Str");
  }
  return res;
}

Fixed version (ground truth):
/** 
 * @param trimDifferential
 * @throws DefinitionException , FHIRException 
 * @throws Exception
 */
private ElementDefinition processPaths(String indent,StructureDefinitionSnapshotComponent result,StructureDefinitionSnapshotComponent base,StructureDefinitionDifferentialComponent differential,int baseCursor,int diffCursor,int baseLimit,int diffLimit,String url,String profileName,String contextPathSrc,String contextPathDst,boolean trimDifferential,String contextName,String resultPathBase,boolean slicingDone,ElementDefinition redirector) throws DefinitionException, FHIRException {
  if (DEBUG)   System.out.println(indent + "String_Node_Str" + resultPathBase+ "String_Node_Str"+ baseCursor+ "String_Node_Str"+ baseLimit+ "String_Node_Str"+ diffCursor+ "String_Node_Str"+ diffLimit+ "String_Node_Str"+ slicingDone+ "String_Node_Str");
  ElementDefinition res=null;
  while (baseCursor <= baseLimit) {
    ElementDefinition currentBase=base.getElement().get(baseCursor);
    String cpath=fixedPathSource(contextPathSrc,currentBase.getPath(),redirector);
    if (DEBUG)     System.out.println(indent + "String_Node_Str" + cpath+ "String_Node_Str"+ baseCursor+ "String_Node_Str"+ baseLimit+ "String_Node_Str"+ diffCursor+ "String_Node_Str"+ diffLimit+ "String_Node_Str"+ slicingDone+ "String_Node_Str");
    List<ElementDefinition> diffMatches=getDiffMatches(differential,cpath,diffCursor,diffLimit,profileName,url);
    if (!currentBase.hasSlicing()) {
      if (diffMatches.isEmpty()) {
        ElementDefinition outcome=updateURLs(url,currentBase.copy());
        outcome.setPath(fixedPathDest(contextPathDst,outcome.getPath(),redirector));
        updateFromBase(outcome,currentBase);
        markDerived(outcome);
        if (resultPathBase == null)         resultPathBase=outcome.getPath();
 else         if (!outcome.getPath().startsWith(resultPathBase))         throw new DefinitionException("String_Node_Str");
        result.getElement().add(outcome);
        if (hasInnerDiffMatches(differential,cpath,diffCursor,diffLimit,base.getElement())) {
          if (outcome.getType().size() > 1) {
            for (            TypeRefComponent t : outcome.getType()) {
              if (!t.getCode().equals("String_Node_Str"))               throw new DefinitionException(diffMatches.get(0).getPath() + "String_Node_Str" + differential.getElement().get(diffCursor).getPath()+ "String_Node_Str"+ typeCode(outcome.getType())+ "String_Node_Str"+ profileName);
            }
          }
          StructureDefinition dt=getProfileForDataType(outcome.getType().get(0));
          if (dt == null)           throw new DefinitionException(cpath + "String_Node_Str" + typeCode(outcome.getType())+ "String_Node_Str"+ profileName+ "String_Node_Str");
          contextName=dt.getUrl();
          int start=diffCursor;
          while (differential.getElement().size() > diffCursor && pathStartsWith(differential.getElement().get(diffCursor).getPath(),cpath + "String_Node_Str"))           diffCursor++;
          processPaths(indent + "String_Node_Str",result,dt.getSnapshot(),differential,1,start,dt.getSnapshot().getElement().size() - 1,diffCursor - 1,url,profileName,cpath,outcome.getPath(),trimDifferential,contextName,resultPathBase,false,null);
        }
        baseCursor++;
      }
 else       if (diffMatches.size() == 1 && (slicingDone || !(diffMatches.get(0).hasSlicing() || (isExtension(diffMatches.get(0)) && diffMatches.get(0).hasSliceName())))) {
        ElementDefinition template=null;
        if (diffMatches.get(0).hasType() && diffMatches.get(0).getType().size() == 1 && diffMatches.get(0).getType().get(0).hasProfile() && !diffMatches.get(0).getType().get(0).getCode().equals("String_Node_Str")) {
          String p=diffMatches.get(0).getType().get(0).getProfile();
          StructureDefinition sd=context.fetchResource(StructureDefinition.class,p);
          if (sd != null) {
            if (!sd.hasSnapshot()) {
              StructureDefinition sdb=context.fetchResource(StructureDefinition.class,sd.getBaseDefinition());
              if (sdb == null)               throw new DefinitionException("String_Node_Str" + sd.getBaseDefinition());
              generateSnapshot(sdb,sd,sd.getUrl(),sd.getName());
            }
            template=sd.getSnapshot().getElement().get(0).copy().setPath(currentBase.getPath());
            template.setSliceName(null);
            if (!diffMatches.get(0).getType().get(0).getCode().equals("String_Node_Str")) {
              template.setMin(currentBase.getMin());
              template.setMax(currentBase.getMax());
            }
          }
        }
        if (template == null)         template=currentBase.copy();
 else         template=overWriteWithCurrent(template,currentBase);
        ElementDefinition outcome=updateURLs(url,template);
        outcome.setPath(fixedPathDest(contextPathDst,outcome.getPath(),redirector));
        res=outcome;
        updateFromBase(outcome,currentBase);
        if (diffMatches.get(0).hasSliceName())         outcome.setSliceName(diffMatches.get(0).getSliceName());
        outcome.setSlicing(null);
        updateFromDefinition(outcome,diffMatches.get(0),profileName,trimDifferential,url);
        if (outcome.getPath().endsWith("String_Node_Str") && outcome.getType().size() == 1 && !outcome.getType().get(0).getCode().equals("String_Node_Str"))         outcome.setPath(outcome.getPath().substring(0,outcome.getPath().length() - 3) + Utilities.capitalize(outcome.getType().get(0).getCode()));
        if (resultPathBase == null)         resultPathBase=outcome.getPath();
 else         if (!outcome.getPath().startsWith(resultPathBase))         throw new DefinitionException("String_Node_Str");
        result.getElement().add(outcome);
        baseCursor++;
        diffCursor=differential.getElement().indexOf(diffMatches.get(0)) + 1;
        if (differential.getElement().size() > diffCursor && outcome.getPath().contains("String_Node_Str") && (isDataType(outcome.getType()) || outcome.hasContentReference())) {
          if (pathStartsWith(differential.getElement().get(diffCursor).getPath(),diffMatches.get(0).getPath() + "String_Node_Str") && !baseWalksInto(base.getElement(),baseCursor)) {
            if (outcome.getType().size() > 1) {
              if (outcome.getPath().endsWith("String_Node_Str") && !diffMatches.get(0).getPath().endsWith("String_Node_Str")) {
                String en=tail(outcome.getPath());
                String tn=tail(diffMatches.get(0).getPath());
                String t=tn.substring(en.length() - 3);
                if (isPrimitive(Utilities.uncapitalize(t)))                 t=Utilities.uncapitalize(t);
                List<TypeRefComponent> ntr=getByTypeName(outcome.getType(),t);
                if (ntr.isEmpty())                 ntr.add(new TypeRefComponent().setCode(t));
                outcome.getType().clear();
                outcome.getType().addAll(ntr);
              }
              if (outcome.getType().size() > 1)               for (              TypeRefComponent t : outcome.getType()) {
                if (!t.getCode().equals("String_Node_Str"))                 throw new DefinitionException(diffMatches.get(0).getPath() + "String_Node_Str" + differential.getElement().get(diffCursor).getPath()+ "String_Node_Str"+ typeCode(outcome.getType())+ "String_Node_Str"+ profileName);
              }
            }
            int start=diffCursor;
            while (differential.getElement().size() > diffCursor && pathStartsWith(differential.getElement().get(diffCursor).getPath(),diffMatches.get(0).getPath() + "String_Node_Str"))             diffCursor++;
            if (outcome.hasContentReference()) {
              ElementDefinition tgt=getElementById(base.getElement(),outcome.getContentReference());
              if (tgt == null)               throw new DefinitionException("String_Node_Str" + outcome.getContentReference());
              replaceFromContentReference(outcome,tgt);
              int nbc=base.getElement().indexOf(tgt) + 1;
              int nbl=nbc;
              while (nbl < base.getElement().size() && base.getElement().get(nbl).getPath().startsWith(tgt.getPath() + "String_Node_Str"))               nbl++;
              processPaths(indent + "String_Node_Str",result,base,differential,nbc,start - 1,nbl - 1,diffCursor - 1,url,profileName,tgt.getPath(),diffMatches.get(0).getPath(),trimDifferential,contextName,resultPathBase,false,outcome);
            }
 else {
              StructureDefinition dt=getProfileForDataType(outcome.getType().get(0));
              if (dt == null)               throw new DefinitionException(diffMatches.get(0).getPath() + "String_Node_Str" + differential.getElement().get(diffCursor).getPath()+ "String_Node_Str"+ typeCode(outcome.getType())+ "String_Node_Str"+ profileName+ "String_Node_Str");
              contextName=dt.getUrl();
              processPaths(indent + "String_Node_Str",result,dt.getSnapshot(),differential,1,start,dt.getSnapshot().getElement().size() - 1,diffCursor - 1,url,profileName + pathTail(diffMatches,0),diffMatches.get(0).getPath(),outcome.getPath(),trimDifferential,contextName,resultPathBase,false,null);
            }
          }
        }
      }
 else {
        if (!unbounded(currentBase) && !isSlicedToOneOnly(diffMatches.get(0)))         throw new DefinitionException("String_Node_Str" + currentBase.getPath() + "String_Node_Str"+ currentBase.getSliceName()+ "String_Node_Str"+ contextName+ "String_Node_Str"+ url);
        if (!diffMatches.get(0).hasSlicing() && !isExtension(currentBase))         throw new DefinitionException("String_Node_Str" + currentBase.getPath() + "String_Node_Str"+ url);
        int start=0;
        int nbl=findEndOfElement(base,baseCursor);
        if (diffMatches.size() > 1 && diffMatches.get(0).hasSlicing() && (nbl > baseCursor || differential.getElement().indexOf(diffMatches.get(1)) > differential.getElement().indexOf(diffMatches.get(0)) + 1)) {
          int ndc=differential.getElement().indexOf(diffMatches.get(0));
          int ndl=findEndOfElement(differential,ndc);
          processPaths(indent + "String_Node_Str",result,base,differential,baseCursor,ndc,nbl,ndl,url,profileName + pathTail(diffMatches,0),contextPathSrc,contextPathDst,trimDifferential,contextName,resultPathBase,true,null).setSlicing(diffMatches.get(0).getSlicing());
          start++;
        }
 else {
          ElementDefinition outcome=updateURLs(url,currentBase.copy());
          outcome.setPath(fixedPathDest(contextPathDst,outcome.getPath(),redirector));
          updateFromBase(outcome,currentBase);
          if (!diffMatches.get(0).hasSlicing())           outcome.setSlicing(makeExtensionSlicing());
 else           outcome.setSlicing(diffMatches.get(0).getSlicing().copy());
          if (!outcome.getPath().startsWith(resultPathBase))           throw new DefinitionException("String_Node_Str");
          result.getElement().add(outcome);
          if (!diffMatches.get(0).hasSliceName()) {
            updateFromDefinition(outcome,diffMatches.get(0),profileName,trimDifferential,url);
            if (!outcome.hasContentReference() && !outcome.hasType()) {
              throw new DefinitionException("String_Node_Str");
            }
            start++;
          }
 else           checkExtensionDoco(outcome);
        }
        int ndc=diffCursor;
        int ndl=diffCursor;
        for (int i=start; i < diffMatches.size(); i++) {
          ndc=differential.getElement().indexOf(diffMatches.get(i));
          ndl=findEndOfElement(differential,ndc);
          processPaths(indent + "String_Node_Str",result,base,differential,baseCursor,ndc,nbl,ndl,url,profileName + pathTail(diffMatches,i),contextPathSrc,contextPathDst,trimDifferential,contextName,resultPathBase,true,null);
        }
        baseCursor=nbl + 1;
        diffCursor=ndl + 1;
      }
    }
 else {
      String path=currentBase.getPath();
      ElementDefinition original=currentBase;
      if (diffMatches.isEmpty()) {
        while (baseCursor < base.getElement().size() && base.getElement().get(baseCursor).getPath().startsWith(path)) {
          ElementDefinition outcome=updateURLs(url,base.getElement().get(baseCursor).copy());
          outcome.setPath(fixedPathDest(contextPathDst,outcome.getPath(),redirector));
          if (!outcome.getPath().startsWith(resultPathBase))           throw new DefinitionException("String_Node_Str" + profileName + "String_Node_Str"+ outcome.getPath()+ "String_Node_Str"+ resultPathBase);
          result.getElement().add(outcome);
          baseCursor++;
        }
      }
 else {
        boolean closed=currentBase.getSlicing().getRules() == SlicingRules.CLOSED;
        int diffpos=0;
        boolean isExtension=cpath.endsWith("String_Node_Str") || cpath.endsWith("String_Node_Str");
        if (diffMatches.get(0).hasSlicing()) {
          ElementDefinitionSlicingComponent dSlice=diffMatches.get(0).getSlicing();
          ElementDefinitionSlicingComponent bSlice=currentBase.getSlicing();
          if (dSlice.hasOrderedElement() && bSlice.hasOrderedElement() && !orderMatches(dSlice.getOrderedElement(),bSlice.getOrderedElement()))           throw new DefinitionException("String_Node_Str" + summarizeSlicing(dSlice) + "String_Node_Str"+ summarizeSlicing(bSlice)+ "String_Node_Str"+ path+ "String_Node_Str"+ contextName+ "String_Node_Str");
          if (!discriminatorMatches(dSlice.getDiscriminator(),bSlice.getDiscriminator()))           throw new DefinitionException("String_Node_Str" + summarizeSlicing(dSlice) + "String_Node_Str"+ summarizeSlicing(bSlice)+ "String_Node_Str"+ path+ "String_Node_Str"+ contextName+ "String_Node_Str");
          if (!ruleMatches(dSlice.getRules(),bSlice.getRules()))           throw new DefinitionException("String_Node_Str" + summarizeSlicing(dSlice) + "String_Node_Str"+ summarizeSlicing(bSlice)+ "String_Node_Str"+ path+ "String_Node_Str"+ contextName+ "String_Node_Str");
        }
        ElementDefinition outcome=updateURLs(url,currentBase.copy());
        outcome.setPath(fixedPathDest(contextPathDst,outcome.getPath(),redirector));
        updateFromBase(outcome,currentBase);
        if (diffMatches.get(0).hasSlicing() || !diffMatches.get(0).hasSliceName()) {
          updateFromSlicing(outcome.getSlicing(),diffMatches.get(0).getSlicing());
          updateFromDefinition(outcome,diffMatches.get(0),profileName,closed,url);
        }
 else         if (!diffMatches.get(0).hasSliceName())         diffMatches.get(0).setUserData(GENERATED_IN_SNAPSHOT,true);
        result.getElement().add(outcome);
        if (!diffMatches.get(0).hasSliceName()) {
          diffpos++;
        }
        if (diffMatches.size() > 1 && diffMatches.get(0).hasSlicing() && differential.getElement().indexOf(diffMatches.get(1)) > differential.getElement().indexOf(diffMatches.get(0)) + 1) {
          int nbl=findEndOfElement(base,baseCursor);
          int ndc=differential.getElement().indexOf(diffMatches.get(0));
          int ndl=findEndOfElement(differential,ndc);
          processPaths(indent + "String_Node_Str",result,base,differential,baseCursor + 1,ndc,nbl,ndl,url,profileName + pathTail(diffMatches,0),contextPathSrc,contextPathDst,trimDifferential,contextName,resultPathBase,true,null);
        }
        List<ElementDefinition> baseMatches=getSiblings(base.getElement(),currentBase);
        for (        ElementDefinition baseItem : baseMatches) {
          baseCursor=base.getElement().indexOf(baseItem);
          outcome=updateURLs(url,baseItem.copy());
          updateFromBase(outcome,currentBase);
          outcome.setPath(fixedPathDest(contextPathDst,outcome.getPath(),redirector));
          outcome.setSlicing(null);
          if (!outcome.getPath().startsWith(resultPathBase))           throw new DefinitionException("String_Node_Str");
          if (diffpos < diffMatches.size() && diffMatches.get(diffpos).getSliceName().equals(outcome.getSliceName())) {
            int nbl=findEndOfElement(base,baseCursor);
            int ndc=differential.getElement().indexOf(diffMatches.get(diffpos));
            int ndl=findEndOfElement(differential,ndc);
            processPaths(indent + "String_Node_Str",result,base,differential,baseCursor,ndc,nbl,ndl,url,profileName + pathTail(diffMatches,diffpos),contextPathSrc,contextPathDst,closed,contextName,resultPathBase,true,null);
            baseCursor=nbl;
            diffCursor=ndl + 1;
            diffpos++;
          }
 else {
            result.getElement().add(outcome);
            baseCursor++;
            while (baseCursor < base.getElement().size() && base.getElement().get(baseCursor).getPath().startsWith(path) && !base.getElement().get(baseCursor).getPath().equals(path)) {
              outcome=updateURLs(url,base.getElement().get(baseCursor).copy());
              outcome.setPath(fixedPathDest(contextPathDst,outcome.getPath(),redirector));
              if (!outcome.getPath().startsWith(resultPathBase))               throw new DefinitionException("String_Node_Str");
              result.getElement().add(outcome);
              baseCursor++;
            }
            baseCursor--;
          }
        }
        if (closed && diffpos < diffMatches.size())         throw new DefinitionException("String_Node_Str" + profileName + "String_Node_Str"+ path+ "String_Node_Str"+ cpath+ "String_Node_Str");
        if (diffpos == diffMatches.size()) {
        }
 else {
          while (diffpos < diffMatches.size()) {
            ElementDefinition diffItem=diffMatches.get(diffpos);
            for (            ElementDefinition baseItem : baseMatches)             if (baseItem.getSliceName().equals(diffItem.getSliceName()))             throw new DefinitionException("String_Node_Str");
            outcome=updateURLs(url,currentBase.copy());
            outcome.setPath(fixedPathDest(contextPathDst,outcome.getPath(),redirector));
            updateFromBase(outcome,currentBase);
            outcome.setSlicing(null);
            if (!outcome.getPath().startsWith(resultPathBase))             throw new DefinitionException("String_Node_Str");
            result.getElement().add(outcome);
            updateFromDefinition(outcome,diffItem,profileName,trimDifferential,url);
            diffCursor=differential.getElement().indexOf(diffItem) + 1;
            if (!outcome.getType().isEmpty() && (differential.getElement().size() > diffCursor) && outcome.getPath().contains("String_Node_Str")&& isDataType(outcome.getType())) {
              if (!baseWalksInto(base.getElement(),baseCursor)) {
                if (differential.getElement().size() > diffCursor && pathStartsWith(differential.getElement().get(diffCursor).getPath(),diffMatches.get(0).getPath() + "String_Node_Str")) {
                  if (outcome.getType().size() > 1)                   for (                  TypeRefComponent t : outcome.getType()) {
                    if (!t.getCode().equals("String_Node_Str"))                     throw new DefinitionException(diffMatches.get(0).getPath() + "String_Node_Str" + differential.getElement().get(diffCursor).getPath()+ "String_Node_Str"+ typeCode(outcome.getType())+ "String_Node_Str"+ profileName);
                  }
                  TypeRefComponent t=outcome.getType().get(0);
                  if (t.getCode().equals("String_Node_Str")) {
                    int baseStart=base.getElement().indexOf(currentBase) + 1;
                    int baseMax=baseStart + 1;
                    while (baseMax < base.getElement().size() && base.getElement().get(baseMax).getPath().startsWith(currentBase.getPath() + "String_Node_Str"))                     baseMax++;
                    int start=diffCursor;
                    while (differential.getElement().size() > diffCursor && pathStartsWith(differential.getElement().get(diffCursor).getPath(),diffMatches.get(0).getPath() + "String_Node_Str"))                     diffCursor++;
                    processPaths(indent + "String_Node_Str",result,base,differential,baseStart,start - 1,baseMax - 1,diffCursor - 1,url,profileName + pathTail(diffMatches,0),base.getElement().get(0).getPath(),outcome.getPath(),trimDifferential,contextName,resultPathBase,false,null);
                  }
 else {
                    StructureDefinition dt=getProfileForDataType(outcome.getType().get(0));
                    if (dt == null)                     throw new DefinitionException(diffMatches.get(0).getPath() + "String_Node_Str" + differential.getElement().get(diffCursor).getPath()+ "String_Node_Str"+ typeCode(outcome.getType())+ "String_Node_Str"+ profileName+ "String_Node_Str");
                    contextName=dt.getUrl();
                    int start=diffCursor;
                    while (differential.getElement().size() > diffCursor && pathStartsWith(differential.getElement().get(diffCursor).getPath(),diffMatches.get(0).getPath() + "String_Node_Str"))                     diffCursor++;
                    processPaths(indent + "String_Node_Str",result,dt.getSnapshot(),differential,1,start - 1,dt.getSnapshot().getElement().size() - 1,diffCursor - 1,url,profileName + pathTail(diffMatches,0),diffMatches.get(0).getPath(),outcome.getPath(),trimDifferential,contextName,resultPathBase,false,null);
                  }
                }
 else                 if (outcome.getType().get(0).getCode().equals("String_Node_Str")) {
                  StructureDefinition dt=getProfileForDataType(outcome.getType().get(0));
                  for (                  ElementDefinition extEd : dt.getSnapshot().getElement()) {
                    if (extEd.getPath().contains("String_Node_Str")) {
                      ElementDefinition extUrlEd=updateURLs(url,extEd.copy());
                      extUrlEd.setPath(fixedPathDest(outcome.getPath(),extUrlEd.getPath(),null));
                      markDerived(extUrlEd);
                      result.getElement().add(extUrlEd);
                    }
                  }
                }
              }
            }
            diffpos++;
          }
        }
        baseCursor++;
      }
    }
  }
  int i=0;
  for (  ElementDefinition e : result.getElement()) {
    i++;
    if (e.hasMinElement() && e.getMinElement().getValue() == null)     throw new Error("String_Node_Str");
  }
  return res;
}