Program: 23929
Project: 23929
Buggy source:
private void generateSnapshot(FetchedFile f,FetchedResource r,StructureDefinition sd) throws Exception {
  boolean changed=false;
  dlog("String_Node_Str" + sd.getUrl());
  ProfileUtilities utils=new ProfileUtilities(context,f.getErrors(),igpkp);
  StructureDefinition base=sd.hasBaseDefinition() ? fetchSnapshotted(sd.getBaseDefinition()) : null;
  if (sd.getKind() != StructureDefinitionKind.LOGICAL) {
    if (!sd.hasSnapshot()) {
      dlog("String_Node_Str" + sd.getUrl());
      if (base == null)       throw new Exception("String_Node_Str" + sd.getBaseDefinition() + "String_Node_Str"+ sd.getUrl()+ "String_Node_Str");
      List<String> errors=new ArrayList<String>();
      utils.sortDifferential(base,sd,"String_Node_Str" + sd.getUrl(),errors);
      for (      String s : errors)       f.getErrors().add(new ValidationMessage(Source.ProfileValidator,IssueType.INVALID,sd.getUrl(),s,IssueSeverity.ERROR));
      utils.setIds(sd,sd.getName());
      String p=sd.getDifferential().getElement().get(0).getPath();
      if (p.contains("String_Node_Str")) {
        changed=true;
        sd.getDifferential().getElement().add(0,new ElementDefinition().setPath(p.substring(0,p.indexOf("String_Node_Str"))));
      }
      utils.generateSnapshot(base,sd,sd.getUrl(),sd.getName());
      changed=true;
    }
  }
 else {
    dlog("String_Node_Str" + sd.getUrl());
    if (base != null && !sd.hasSnapshot()) {
      utils.populateLogicalSnapshot(sd);
      changed=true;
    }
  }
  if (changed || (!r.getElement().hasChild("String_Node_Str") && sd.hasSnapshot()))   r.setElement(new ObjectConverter(context).convert(sd));
  r.setSnapshotted(true);
  dlog("String_Node_Str" + sd.getUrl());
  context.seeResource(sd.getUrl(),sd);
}

Fixed version (ground truth):
private void generateSnapshot(FetchedFile f,FetchedResource r,StructureDefinition sd) throws Exception {
  boolean changed=false;
  dlog("String_Node_Str" + sd.getUrl());
  ProfileUtilities utils=new ProfileUtilities(context,f.getErrors(),igpkp);
  StructureDefinition base=sd.hasBaseDefinition() ? fetchSnapshotted(sd.getBaseDefinition()) : null;
  if (sd.getKind() != StructureDefinitionKind.LOGICAL) {
    if (!sd.hasSnapshot()) {
      dlog("String_Node_Str" + sd.getUrl());
      if (base == null)       throw new Exception("String_Node_Str" + sd.getBaseDefinition() + "String_Node_Str"+ sd.getUrl()+ "String_Node_Str");
      List<String> errors=new ArrayList<String>();
      utils.sortDifferential(base,sd,"String_Node_Str" + sd.getUrl(),errors);
      for (      String s : errors)       f.getErrors().add(new ValidationMessage(Source.ProfileValidator,IssueType.INVALID,sd.getUrl(),s,IssueSeverity.ERROR));
      utils.setIds(sd,sd.getName());
      String p=sd.getDifferential().getElement().get(0).getPath();
      if (p.contains("String_Node_Str")) {
        changed=true;
        sd.getDifferential().getElement().add(0,new ElementDefinition().setPath(p.substring(0,p.indexOf("String_Node_Str"))));
      }
      utils.generateSnapshot(base,sd,sd.getUrl(),sd.getName());
      changed=true;
    }
  }
 else {
    dlog("String_Node_Str" + sd.getUrl());
    if (base != null && !sd.hasSnapshot()) {
      utils.populateLogicalSnapshot(sd);
      changed=true;
    }
  }
  if (changed || (!r.getElement().hasChild("String_Node_Str") && sd.hasSnapshot()))   r.setElement(convertToElement(sd));
  r.setSnapshotted(true);
  dlog("String_Node_Str" + sd.getUrl());
  context.seeResource(sd.getUrl(),sd);
}