Program: 24158
Project: 24158
Buggy source:
private Profile produceProfile(String filename,ProfileDefn profile,String filePath,String master,Map<String,Example> examples) throws Exception {
  File tmp=Utilities.createTempFile("String_Node_Str","String_Node_Str");
  String title=filename.contains("String_Node_Str") ? filename.substring(0,filename.lastIndexOf("String_Node_Str")) : filename;
  XmlSpecGenerator gen=new XmlSpecGenerator(new FileOutputStream(tmp),null,"String_Node_Str",page);
  gen.generate(profile,"String_Node_Str" + title);
  gen.close();
  String xml=TextFile.fileToString(tmp.getAbsolutePath());
  ProfileGenerator pgen=new ProfileGenerator(page.getDefinitions(),page.getWorkerContext());
  Profile p=pgen.generate(profile,title,xml,page.getGenDate());
  XmlComposer comp=new XmlComposer();
  comp.compose(new FileOutputStream(page.getFolders().dstDir + title + "String_Node_Str"),p,true,false);
  Utilities.copyFile(new CSFile(page.getFolders().dstDir + title + "String_Node_Str"),new CSFile(page.getFolders().dstDir + "String_Node_Str" + File.separator+ title+ "String_Node_Str"));
  JsonComposer jcomp=new JsonComposer();
  jcomp.compose(new FileOutputStream(page.getFolders().dstDir + title + "String_Node_Str"),p,true);
  TerminologyNotesGenerator tgen=new TerminologyNotesGenerator(new FileOutputStream(tmp),page);
  tgen.generate(profile,page.getDefinitions().getBindings());
  tgen.close();
  String tx=TextFile.fileToString(tmp.getAbsolutePath());
  String introAndNotesPath=Utilities.path(page.getFolders().rootDir,"String_Node_Str");
  if (master != null)   introAndNotesPath=Utilities.path(page.getFolders().rootDir,"String_Node_Str",master.toLowerCase());
  String intro=null;
  if (profile.getMetadata().containsKey("String_Node_Str") && !Utilities.noString(profile.getMetadata().get("String_Node_Str").get(0))) {
    intro=page.loadXmlNotesFromFile(introAndNotesPath + File.separator + profile.getMetadata().get("String_Node_Str").get(0),false,null,null);
  }
  String notes=null;
  if (profile.getMetadata().containsKey("String_Node_Str") && !Utilities.noString(profile.getMetadata().get("String_Node_Str").get(0)))   notes=page.loadXmlNotesFromFile(introAndNotesPath + File.separator + profile.getMetadata().get("String_Node_Str").get(0),false,null,null);
  String exXml="String_Node_Str";
  if (examples != null) {
    for (    String en : examples.keySet()) {
      String ep=examples.get(en).getPath().getAbsolutePath();
      String n=Utilities.changeFileExt(en,"String_Node_Str");
      DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
      factory.setNamespaceAware(true);
      DocumentBuilder builder=factory.newDocumentBuilder();
      Document xdoc=builder.parse(new CSFileInputStream(ep));
      XmlGenerator xmlgen=new XmlGenerator();
      File dst=new File(page.getFolders().dstDir + en);
      xmlgen.generate(xdoc.getDocumentElement(),dst,xdoc.getDocumentElement().getLocalName().equals("String_Node_Str") ? "String_Node_Str" : "String_Node_Str",xdoc.getDocumentElement().getLocalName());
      builder=factory.newDocumentBuilder();
      xdoc=builder.parse(new CSFileInputStream(dst.getAbsolutePath()));
      XhtmlGenerator xhtml=new XhtmlGenerator(null);
      exXml=xhtml.generateInsert(xdoc,"String_Node_Str" + profile.metadata("String_Node_Str"),null);
      cloneToXhtml(n,"String_Node_Str" + profile.metadata("String_Node_Str"),true,"String_Node_Str");
      String json;
      try {
        json=javaReferencePlatform.convertToJson(page.getFolders().dstDir,page.getFolders().dstDir + n + "String_Node_Str",page.getFolders().dstDir + n + "String_Node_Str");
      }
 catch (      Throwable t) {
        System.out.println("String_Node_Str" + page.getFolders().dstDir + n+ "String_Node_Str");
        t.printStackTrace(System.err);
        TextFile.stringToFile(t.getMessage(),page.getFolders().dstDir + n + "String_Node_Str");
        json=t.getMessage();
      }
      String head="String_Node_Str" + Utilities.escapeXml("String_Node_Str" + profile.metadata("String_Node_Str")) + "String_Node_Str"+ "String_Node_Str"+ Utilities.escapeXml("String_Node_Str" + profile.metadata("String_Node_Str"))+ "String_Node_Str"+ n+ "String_Node_Str";
      String tail="String_Node_Str";
      TextFile.stringToFile(head + Utilities.escapeXml(json) + tail,page.getFolders().dstDir + n + "String_Node_Str");
      page.getEpub().registerFile(n + "String_Node_Str","String_Node_Str" + profile.metadata("String_Node_Str"),EPubManager.XHTML_TYPE);
    }
  }
  String src=TextFile.fileToString(page.getFolders().srcDir + "String_Node_Str");
  src=page.processProfileIncludes(filename,profile,xml,tx,src,exXml,intro,notes,master,title + "String_Node_Str",null,filename,examples);
  page.getEpub().registerFile(title + "String_Node_Str","String_Node_Str" + profile.getSource().getNameSimple(),EPubManager.XHTML_TYPE);
  TextFile.stringToFile(src,page.getFolders().dstDir + title + "String_Node_Str");
  for (  ProfileStructureComponent s : profile.getSource().getStructure()) {
    String fn=Utilities.changeFileExt(filename,"String_Node_Str" + Utilities.getFileNameForName(s.getNameSimple())) + "String_Node_Str";
    src=TextFile.fileToString(page.getFolders().srcDir + "String_Node_Str");
    src=page.processProfileIncludes(fn,profile,"String_Node_Str",tx,src,exXml,intro,notes,master,title + "String_Node_Str",s,filename,examples);
    page.getEpub().registerFile(fn,"String_Node_Str" + profile.getSource().getNameSimple() + "String_Node_Str"+ s.getNameSimple(),EPubManager.XHTML_TYPE);
    TextFile.stringToFile(src,page.getFolders().dstDir + fn);
  }
  src=TextFile.fileToString(page.getFolders().srcDir + "String_Node_Str");
  src=page.processProfileIncludes(filename,profile,xml,tx,src,exXml,intro,notes,master,title + "String_Node_Str",null,filename,examples);
  page.getEpub().registerFile(title + "String_Node_Str","String_Node_Str" + profile.getSource().getNameSimple(),EPubManager.XHTML_TYPE);
  TextFile.stringToFile(src,page.getFolders().dstDir + title + "String_Node_Str");
  src=TextFile.fileToString(page.getFolders().srcDir + "String_Node_Str");
  src=page.processProfileIncludes(filename,profile,xml,tx,src,exXml,intro,notes,master,title + "String_Node_Str",null,filename,examples);
  page.getEpub().registerFile(title + "String_Node_Str","String_Node_Str" + profile.getSource().getNameSimple(),EPubManager.XHTML_TYPE);
  TextFile.stringToFile(src,page.getFolders().dstDir + title + "String_Node_Str");
  src=TextFile.fileToString(page.getFolders().srcDir + "String_Node_Str");
  src=page.processProfileIncludes(filename,profile,xml,tx,src,exXml,intro,notes,master,title + "String_Node_Str",null,filename,examples);
  page.getEpub().registerFile(title + "String_Node_Str","String_Node_Str" + profile.getSource().getNameSimple(),EPubManager.XHTML_TYPE);
  TextFile.stringToFile(src,page.getFolders().dstDir + title + "String_Node_Str");
  DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
  factory.setNamespaceAware(true);
  DocumentBuilder builder=factory.newDocumentBuilder();
  Document xdoc=builder.parse(new CSFileInputStream(page.getFolders().dstDir + title + "String_Node_Str"));
  XmlGenerator xmlgen=new XmlGenerator();
  xmlgen.generate(xdoc.getDocumentElement(),tmp,"String_Node_Str",xdoc.getDocumentElement().getLocalName());
  builder=factory.newDocumentBuilder();
  xdoc=builder.parse(new CSFileInputStream(tmp.getAbsolutePath()));
  XhtmlGenerator xhtml=new XhtmlGenerator(new ExampleAdorner(page.getDefinitions()));
  ByteArrayOutputStream b=new ByteArrayOutputStream();
  xhtml.generate(xdoc,b,"String_Node_Str",profile.metadata("String_Node_Str"),0,true,title + "String_Node_Str");
  String html=TextFile.fileToString(page.getFolders().srcDir + "String_Node_Str").replace("String_Node_Str",b.toString());
  html=page.processProfileIncludes(title + "String_Node_Str",profile,"String_Node_Str","String_Node_Str",html,"String_Node_Str","String_Node_Str","String_Node_Str",master,title + "String_Node_Str",null,filename,examples);
  TextFile.stringToFile(html,page.getFolders().dstDir + title + "String_Node_Str");
  page.getEpub().registerFile(title + "String_Node_Str","String_Node_Str",EPubManager.XHTML_TYPE);
  String n=title + "String_Node_Str";
  String json=resource2Json(p);
  json="String_Node_Str" + Utilities.escapeXml("String_Node_Str" + profile.metadata("String_Node_Str")) + "String_Node_Str"+ Utilities.escapeXml(json)+ "String_Node_Str";
  html=TextFile.fileToString(page.getFolders().srcDir + "String_Node_Str").replace("String_Node_Str",json);
  html=page.processProfileIncludes(title + "String_Node_Str",profile,"String_Node_Str","String_Node_Str",html,"String_Node_Str","String_Node_Str","String_Node_Str",master,title + "String_Node_Str",null,filename,examples);
  TextFile.stringToFile(html,page.getFolders().dstDir + title + "String_Node_Str");
  page.getEpub().registerExternal(n + "String_Node_Str");
  tmp.delete();
  return p;
}

Fixed version (ground truth):
private Profile produceProfile(String filename,ProfileDefn profile,String filePath,String master,Map<String,Example> examples) throws Exception {
  File tmp=Utilities.createTempFile("String_Node_Str","String_Node_Str");
  String title=filename.contains("String_Node_Str") ? filename.substring(0,filename.lastIndexOf("String_Node_Str")) : filename;
  XmlSpecGenerator gen=new XmlSpecGenerator(new FileOutputStream(tmp),null,"String_Node_Str",page);
  gen.generate(profile,"String_Node_Str" + title);
  gen.close();
  String xml=TextFile.fileToString(tmp.getAbsolutePath());
  ProfileGenerator pgen=new ProfileGenerator(page.getDefinitions(),page.getWorkerContext());
  Profile p=pgen.generate(profile,title,xml,page.getGenDate());
  XmlComposer comp=new XmlComposer();
  comp.compose(new FileOutputStream(page.getFolders().dstDir + title + "String_Node_Str"),p,true,false);
  Utilities.copyFile(new CSFile(page.getFolders().dstDir + title + "String_Node_Str"),new CSFile(page.getFolders().dstDir + "String_Node_Str" + File.separator+ title+ "String_Node_Str"));
  JsonComposer jcomp=new JsonComposer();
  jcomp.compose(new FileOutputStream(page.getFolders().dstDir + title + "String_Node_Str"),p,true);
  TerminologyNotesGenerator tgen=new TerminologyNotesGenerator(new FileOutputStream(tmp),page);
  tgen.generate(profile,page.getDefinitions().getBindings());
  tgen.close();
  String tx=TextFile.fileToString(tmp.getAbsolutePath());
  String introAndNotesPath=Utilities.path(page.getFolders().rootDir,"String_Node_Str");
  if (master != null)   introAndNotesPath=Utilities.path(page.getFolders().rootDir,"String_Node_Str",master.toLowerCase());
  String intro=null;
  if (profile.getMetadata().containsKey("String_Node_Str") && !Utilities.noString(profile.getMetadata().get("String_Node_Str").get(0))) {
    intro=page.loadXmlNotesFromFile(introAndNotesPath + File.separator + profile.getMetadata().get("String_Node_Str").get(0),false,null,null);
  }
  String notes=null;
  if (profile.getMetadata().containsKey("String_Node_Str") && !Utilities.noString(profile.getMetadata().get("String_Node_Str").get(0)))   notes=page.loadXmlNotesFromFile(introAndNotesPath + File.separator + profile.getMetadata().get("String_Node_Str").get(0),false,null,null);
  String exXml="String_Node_Str";
  if (examples != null) {
    for (    String en : examples.keySet()) {
      String ep=examples.get(en).getPath().getAbsolutePath();
      String n=Utilities.changeFileExt(en,"String_Node_Str");
      DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
      factory.setNamespaceAware(true);
      DocumentBuilder builder=factory.newDocumentBuilder();
      Document xdoc=builder.parse(new CSFileInputStream(ep));
      XmlGenerator xmlgen=new XmlGenerator();
      File dst=new File(page.getFolders().dstDir + en);
      xmlgen.generate(xdoc.getDocumentElement(),dst,xdoc.getDocumentElement().getLocalName().equals("String_Node_Str") ? "String_Node_Str" : "String_Node_Str",xdoc.getDocumentElement().getLocalName());
      builder=factory.newDocumentBuilder();
      xdoc=builder.parse(new CSFileInputStream(dst.getAbsolutePath()));
      XhtmlGenerator xhtml=new XhtmlGenerator(null);
      exXml=xhtml.generateInsert(xdoc,"String_Node_Str" + profile.metadata("String_Node_Str"),null);
      cloneToXhtml(n,"String_Node_Str" + profile.metadata("String_Node_Str"),true,"String_Node_Str");
      String json;
      try {
        json=javaReferencePlatform.convertToJson(page.getFolders().dstDir,page.getFolders().dstDir + n + "String_Node_Str",page.getFolders().dstDir + n + "String_Node_Str");
      }
 catch (      Throwable t) {
        System.out.println("String_Node_Str" + page.getFolders().dstDir + n+ "String_Node_Str");
        t.printStackTrace(System.err);
        TextFile.stringToFile(t.getMessage(),page.getFolders().dstDir + n + "String_Node_Str");
        json=t.getMessage();
      }
      String head="String_Node_Str" + Utilities.escapeXml("String_Node_Str" + profile.metadata("String_Node_Str")) + "String_Node_Str"+ "String_Node_Str"+ Utilities.escapeXml("String_Node_Str" + profile.metadata("String_Node_Str"))+ "String_Node_Str"+ n+ "String_Node_Str";
      String tail="String_Node_Str";
      TextFile.stringToFile(head + Utilities.escapeXml(json) + tail,page.getFolders().dstDir + n + "String_Node_Str");
      page.getEpub().registerFile(n + "String_Node_Str","String_Node_Str" + profile.metadata("String_Node_Str"),EPubManager.XHTML_TYPE);
    }
  }
  String src=TextFile.fileToString(page.getFolders().srcDir + "String_Node_Str");
  src=page.processProfileIncludes(filename,profile,xml,tx,src,exXml,intro,notes,master,title + "String_Node_Str",null,filename,examples);
  page.getEpub().registerFile(title + "String_Node_Str","String_Node_Str" + profile.getSource().getNameSimple(),EPubManager.XHTML_TYPE);
  TextFile.stringToFile(src,page.getFolders().dstDir + title + "String_Node_Str");
  for (  ProfileStructureComponent s : profile.getSource().getStructure()) {
    String fn=Utilities.changeFileExt(filename,"String_Node_Str" + Utilities.getFileNameForName(s.getNameSimple())) + "String_Node_Str";
    src=TextFile.fileToString(page.getFolders().srcDir + "String_Node_Str");
    src=page.processProfileIncludes(fn,profile,"String_Node_Str",tx,src,exXml,intro,notes,master,title + "String_Node_Str",s,filename,examples);
    page.getEpub().registerFile(fn,"String_Node_Str" + profile.getSource().getNameSimple() + "String_Node_Str"+ s.getNameSimple(),EPubManager.XHTML_TYPE);
    TextFile.stringToFile(src,page.getFolders().dstDir + fn);
  }
  src=TextFile.fileToString(page.getFolders().srcDir + "String_Node_Str");
  src=page.processProfileIncludes(filename,profile,xml,tx,src,exXml,intro,notes,master,title + "String_Node_Str",null,filename,examples);
  page.getEpub().registerFile(title + "String_Node_Str","String_Node_Str" + profile.getSource().getNameSimple(),EPubManager.XHTML_TYPE);
  TextFile.stringToFile(src,page.getFolders().dstDir + title + "String_Node_Str");
  src=TextFile.fileToString(page.getFolders().srcDir + "String_Node_Str");
  src=page.processProfileIncludes(filename,profile,xml,tx,src,exXml,intro,notes,master,title + "String_Node_Str",null,filename,examples);
  page.getEpub().registerFile(title + "String_Node_Str","String_Node_Str" + profile.getSource().getNameSimple(),EPubManager.XHTML_TYPE);
  TextFile.stringToFile(src,page.getFolders().dstDir + title + "String_Node_Str");
  src=TextFile.fileToString(page.getFolders().srcDir + "String_Node_Str");
  src=page.processProfileIncludes(filename,profile,xml,tx,src,exXml,intro,notes,master,title + "String_Node_Str",null,filename,examples);
  page.getEpub().registerFile(title + "String_Node_Str","String_Node_Str" + profile.getSource().getNameSimple(),EPubManager.XHTML_TYPE);
  TextFile.stringToFile(src,page.getFolders().dstDir + title + "String_Node_Str");
  new ReviewSpreadsheetGenerator().generate(page.getFolders().dstDir + title + "String_Node_Str","String_Node_Str",page.getGenDate(),profile.getSource());
  DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
  factory.setNamespaceAware(true);
  DocumentBuilder builder=factory.newDocumentBuilder();
  Document xdoc=builder.parse(new CSFileInputStream(page.getFolders().dstDir + title + "String_Node_Str"));
  XmlGenerator xmlgen=new XmlGenerator();
  xmlgen.generate(xdoc.getDocumentElement(),tmp,"String_Node_Str",xdoc.getDocumentElement().getLocalName());
  builder=factory.newDocumentBuilder();
  xdoc=builder.parse(new CSFileInputStream(tmp.getAbsolutePath()));
  XhtmlGenerator xhtml=new XhtmlGenerator(new ExampleAdorner(page.getDefinitions()));
  ByteArrayOutputStream b=new ByteArrayOutputStream();
  xhtml.generate(xdoc,b,"String_Node_Str",profile.metadata("String_Node_Str"),0,true,title + "String_Node_Str");
  String html=TextFile.fileToString(page.getFolders().srcDir + "String_Node_Str").replace("String_Node_Str",b.toString());
  html=page.processProfileIncludes(title + "String_Node_Str",profile,"String_Node_Str","String_Node_Str",html,"String_Node_Str","String_Node_Str","String_Node_Str",master,title + "String_Node_Str",null,filename,examples);
  TextFile.stringToFile(html,page.getFolders().dstDir + title + "String_Node_Str");
  page.getEpub().registerFile(title + "String_Node_Str","String_Node_Str",EPubManager.XHTML_TYPE);
  String n=title + "String_Node_Str";
  String json=resource2Json(p);
  json="String_Node_Str" + Utilities.escapeXml("String_Node_Str" + profile.metadata("String_Node_Str")) + "String_Node_Str"+ Utilities.escapeXml(json)+ "String_Node_Str";
  html=TextFile.fileToString(page.getFolders().srcDir + "String_Node_Str").replace("String_Node_Str",json);
  html=page.processProfileIncludes(title + "String_Node_Str",profile,"String_Node_Str","String_Node_Str",html,"String_Node_Str","String_Node_Str","String_Node_Str",master,title + "String_Node_Str",null,filename,examples);
  TextFile.stringToFile(html,page.getFolders().dstDir + title + "String_Node_Str");
  page.getEpub().registerExternal(n + "String_Node_Str");
  tmp.delete();
  return p;
}