Program: 23301
Project: 23301
Buggy source:
/** 
 * @param trimDifferential
 * @throws DefinitionException , FHIRException 
 * @throws Exception
 */
private void processPaths(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) throws DefinitionException, FHIRException {
  while (baseCursor <= baseLimit) {
    ElementDefinition currentBase=base.getElement().get(baseCursor);
    String cpath=fixedPath(contextPathSrc,currentBase.getPath());
    List<ElementDefinition> diffMatches=getDiffMatches(differential,cpath,diffCursor,diffLimit,profileName,url);
    if (!currentBase.hasSlicing()) {
      if (diffMatches.isEmpty()) {
        ElementDefinition outcome=updateURLs(url,currentBase.copy());
        outcome.setPath(fixedPath(contextPathDst,outcome.getPath()));
        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);
        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(fixedPath(contextPathDst,outcome.getPath()));
        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())) {
          if (pathStartsWith(differential.getElement().get(diffCursor).getPath(),diffMatches.get(0).getPath() + "String_Node_Str") && !baseWalksInto(base.getElement(),baseCursor)) {
            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(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(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);
          }
        }
      }
 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);
        ElementDefinition outcome=updateURLs(url,currentBase.copy());
        outcome.setPath(fixedPath(contextPathDst,outcome.getPath()));
        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);
        int start=0;
        boolean skipSlicingElement=false;
        if (!diffMatches.get(0).hasSliceName()) {
          updateFromDefinition(outcome,diffMatches.get(0),profileName,trimDifferential,url);
          if (!outcome.hasType()) {
            throw new DefinitionException("String_Node_Str");
          }
          skipSlicingElement=true;
        }
 else         checkExtensionDoco(outcome);
        int nbl=findEndOfElement(base,baseCursor);
        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);
          if (skipSlicingElement && i == 0) {
            ndc=ndc + 1;
            if (ndc > ndl)             continue;
          }
          processPaths(result,base,differential,baseCursor,ndc,nbl,ndl,url,profileName + pathTail(diffMatches,i),contextPathSrc,contextPathDst,trimDifferential,contextName,resultPathBase,true);
        }
        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(fixedPath(contextPathDst,outcome.getPath()));
          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()) {
          if (!isExtension)           diffpos++;
          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" + summariseSlicing(dSlice) + "String_Node_Str"+ summariseSlicing(bSlice)+ "String_Node_Str"+ path+ "String_Node_Str"+ contextName+ "String_Node_Str");
          if (!discriminatorMatches(dSlice.getDiscriminator(),bSlice.getDiscriminator()))           throw new DefinitionException("String_Node_Str" + summariseSlicing(dSlice) + "String_Node_Str"+ summariseSlicing(bSlice)+ "String_Node_Str"+ path+ "String_Node_Str"+ contextName+ "String_Node_Str");
          if (!ruleMatches(dSlice.getRules(),bSlice.getRules()))           throw new DefinitionException("String_Node_Str" + summariseSlicing(dSlice) + "String_Node_Str"+ summariseSlicing(bSlice)+ "String_Node_Str"+ path+ "String_Node_Str"+ contextName+ "String_Node_Str");
        }
        ElementDefinition outcome=updateURLs(url,currentBase.copy());
        outcome.setPath(fixedPath(contextPathDst,outcome.getPath()));
        updateFromBase(outcome,currentBase);
        if (diffMatches.get(0).hasSlicing() && !isExtension) {
          updateFromSlicing(outcome.getSlicing(),diffMatches.get(0).getSlicing());
          updateFromDefinition(outcome,diffMatches.get(0),profileName,closed,url);
        }
        if (diffMatches.get(0).hasSlicing() && !diffMatches.get(0).hasSliceName()) {
          if (isExtension)           diffpos++;
        }
        result.getElement().add(outcome);
        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(fixedPath(contextPathDst,outcome.getPath()));
          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(result,base,differential,baseCursor,ndc,nbl,ndl,url,profileName + pathTail(diffMatches,diffpos),contextPathSrc,contextPathDst,closed,contextName,resultPathBase,true);
            baseCursor=nbl + 1;
            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(fixedPath(contextPathDst,outcome.getPath()));
              if (!outcome.getPath().startsWith(resultPathBase))               throw new DefinitionException("String_Node_Str");
              result.getElement().add(outcome);
              baseCursor++;
            }
          }
        }
        if (closed && diffpos < diffMatches.size())         throw new DefinitionException("String_Node_Str" + profileName + "String_Node_Str"+ path+ "String_Node_Str"+ cpath+ "String_Node_Str");
        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(fixedPath(contextPathDst,outcome.getPath()));
          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() && (outcome.getType().get(0).getCode().equals("String_Node_Str") || 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);
                }
                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(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);
              }
 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(fixedPath(outcome.getPath(),extUrlEd.getPath()));
                    markDerived(extUrlEd);
                    result.getElement().add(extUrlEd);
                  }
                }
              }
            }
          }
          diffpos++;
        }
      }
    }
  }
  int i=0;
  for (  ElementDefinition e : result.getElement()) {
    i++;
    if (e.hasMinElement() && e.getMinElement().getValue() == null)     throw new Error("String_Node_Str");
  }
}

Fixed version (ground truth):
/** 
 * @param trimDifferential
 * @throws DefinitionException , FHIRException 
 * @throws Exception
 */
private void processPaths(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) throws DefinitionException, FHIRException {
  while (baseCursor <= baseLimit) {
    ElementDefinition currentBase=base.getElement().get(baseCursor);
    String cpath=fixedPath(contextPathSrc,currentBase.getPath());
    List<ElementDefinition> diffMatches=getDiffMatches(differential,cpath,diffCursor,diffLimit,profileName,url);
    if (!currentBase.hasSlicing()) {
      if (diffMatches.isEmpty()) {
        ElementDefinition outcome=updateURLs(url,currentBase.copy());
        outcome.setPath(fixedPath(contextPathDst,outcome.getPath()));
        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);
        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(fixedPath(contextPathDst,outcome.getPath()));
        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())) {
          if (pathStartsWith(differential.getElement().get(diffCursor).getPath(),diffMatches.get(0).getPath() + "String_Node_Str") && !baseWalksInto(base.getElement(),baseCursor)) {
            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(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(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);
          }
        }
      }
 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);
        ElementDefinition outcome=updateURLs(url,currentBase.copy());
        outcome.setPath(fixedPath(contextPathDst,outcome.getPath()));
        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);
        int start=0;
        boolean skipSlicingElement=false;
        if (!diffMatches.get(0).hasSliceName()) {
          updateFromDefinition(outcome,diffMatches.get(0),profileName,trimDifferential,url);
          if (!outcome.hasType()) {
            throw new DefinitionException("String_Node_Str");
          }
          result.getElement().remove(result.getElement().size() - 1);
          skipSlicingElement=true;
        }
 else         checkExtensionDoco(outcome);
        int nbl=findEndOfElement(base,baseCursor);
        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(result,base,differential,baseCursor,ndc,nbl,ndl,url,profileName + pathTail(diffMatches,i),contextPathSrc,contextPathDst,trimDifferential,contextName,resultPathBase,true);
        }
        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(fixedPath(contextPathDst,outcome.getPath()));
          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()) {
          if (!isExtension)           diffpos++;
          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" + summariseSlicing(dSlice) + "String_Node_Str"+ summariseSlicing(bSlice)+ "String_Node_Str"+ path+ "String_Node_Str"+ contextName+ "String_Node_Str");
          if (!discriminatorMatches(dSlice.getDiscriminator(),bSlice.getDiscriminator()))           throw new DefinitionException("String_Node_Str" + summariseSlicing(dSlice) + "String_Node_Str"+ summariseSlicing(bSlice)+ "String_Node_Str"+ path+ "String_Node_Str"+ contextName+ "String_Node_Str");
          if (!ruleMatches(dSlice.getRules(),bSlice.getRules()))           throw new DefinitionException("String_Node_Str" + summariseSlicing(dSlice) + "String_Node_Str"+ summariseSlicing(bSlice)+ "String_Node_Str"+ path+ "String_Node_Str"+ contextName+ "String_Node_Str");
        }
        ElementDefinition outcome=updateURLs(url,currentBase.copy());
        outcome.setPath(fixedPath(contextPathDst,outcome.getPath()));
        updateFromBase(outcome,currentBase);
        if (diffMatches.get(0).hasSlicing() && !isExtension) {
          updateFromSlicing(outcome.getSlicing(),diffMatches.get(0).getSlicing());
          updateFromDefinition(outcome,diffMatches.get(0),profileName,closed,url);
        }
        if (diffMatches.get(0).hasSlicing() && !diffMatches.get(0).hasSliceName()) {
          if (isExtension)           diffpos++;
        }
        result.getElement().add(outcome);
        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(fixedPath(contextPathDst,outcome.getPath()));
          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(result,base,differential,baseCursor,ndc,nbl,ndl,url,profileName + pathTail(diffMatches,diffpos),contextPathSrc,contextPathDst,closed,contextName,resultPathBase,true);
            baseCursor=nbl + 1;
            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(fixedPath(contextPathDst,outcome.getPath()));
              if (!outcome.getPath().startsWith(resultPathBase))               throw new DefinitionException("String_Node_Str");
              result.getElement().add(outcome);
              baseCursor++;
            }
          }
        }
        if (closed && diffpos < diffMatches.size())         throw new DefinitionException("String_Node_Str" + profileName + "String_Node_Str"+ path+ "String_Node_Str"+ cpath+ "String_Node_Str");
        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(fixedPath(contextPathDst,outcome.getPath()));
          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() && (outcome.getType().get(0).getCode().equals("String_Node_Str") || 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);
                }
                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(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);
              }
 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(fixedPath(outcome.getPath(),extUrlEd.getPath()));
                    markDerived(extUrlEd);
                    result.getElement().add(extUrlEd);
                  }
                }
              }
            }
          }
          diffpos++;
        }
      }
    }
  }
  int i=0;
  for (  ElementDefinition e : result.getElement()) {
    i++;
    if (e.hasMinElement() && e.getMinElement().getValue() == null)     throw new Error("String_Node_Str");
  }
}