Program: 24175
Project: 24175
Buggy source:
private Profile produceProfile(String filename,ProfileDefn profile,String examplePath,String exampleName,String master) throws Exception {
  File tmp=File.createTempFile("String_Node_Str","String_Node_Str");
  tmp.deleteOnExit();
  String title=filename.contains("String_Node_Str") ? filename.substring(0,filename.lastIndexOf("String_Node_Str")) : filename;
  validateProfile(profile);
  XmlSpecGenerator gen=new XmlSpecGenerator(new FileOutputStream(tmp),null,"String_Node_Str",page);
  gen.generate(profile);
  gen.close();
  String xml=TextFile.fileToString(tmp.getAbsolutePath());
  ProfileGenerator pgen=new ProfileGenerator(page.getDefinitions());
  Profile p=pgen.generate(profile,xml,GenerationMode.Resource);
  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=null;
  if (examplePath != null)   introAndNotesPath=Utilities.getDirectoryForFile(examplePath);
 else   introAndNotesPath=Utilities.path(page.getFolders().rootDir,"String_Node_Str");
  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),true,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 (examplePath != null) {
    String n=Utilities.changeFileExt(exampleName,"String_Node_Str");
    DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder builder=factory.newDocumentBuilder();
    Document xdoc=builder.parse(new CSFileInputStream(examplePath));
    XmlGenerator xmlgen=new XmlGenerator();
    File dst=new File(page.getFolders().dstDir + exampleName);
    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);
  page.getEpub().registerFile(title + "String_Node_Str","String_Node_Str" + exampleName,EPubManager.XHTML_TYPE);
  TextFile.stringToFile(src,page.getFolders().dstDir + title + "String_Node_Str");
  page.getEpub().registerFile(title + "String_Node_Str","String_Node_Str" + exampleName,EPubManager.XHTML_TYPE);
  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.processPageIncludes(title + "String_Node_Str",html,master == null ? "String_Node_Str" : "String_Node_Str" + master,null);
  TextFile.stringToFile(html,page.getFolders().dstDir + title + "String_Node_Str");
  page.getEpub().registerFile(title + "String_Node_Str","String_Node_Str",EPubManager.XHTML_TYPE);
  jsonToXhtml(title + "String_Node_Str","String_Node_Str" + profile.metadata("String_Node_Str"),resource2Json(p),master == null ? "String_Node_Str" : "String_Node_Str" + master);
  tmp.delete();
  return p;
}

Fixed version (ground truth):
private Profile produceProfile(String filename,ProfileDefn profile,String examplePath,String filePath,String exampleName,String master) throws Exception {
  File tmp=File.createTempFile("String_Node_Str","String_Node_Str");
  tmp.deleteOnExit();
  String title=filename.contains("String_Node_Str") ? filename.substring(0,filename.lastIndexOf("String_Node_Str")) : filename;
  validateProfile(profile);
  XmlSpecGenerator gen=new XmlSpecGenerator(new FileOutputStream(tmp),null,"String_Node_Str",page);
  gen.generate(profile);
  gen.close();
  String xml=TextFile.fileToString(tmp.getAbsolutePath());
  ProfileGenerator pgen=new ProfileGenerator(page.getDefinitions());
  Profile p=pgen.generate(profile,xml,GenerationMode.Resource);
  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=null;
  if (examplePath != null)   introAndNotesPath=Utilities.getDirectoryForFile(examplePath);
 else   if (exampleName == "String_Node_Str")   introAndNotesPath=Utilities.getDirectoryForFile(filePath);
 else   introAndNotesPath=Utilities.path(page.getFolders().rootDir,"String_Node_Str");
  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),true,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 (examplePath != null) {
    String n=Utilities.changeFileExt(exampleName,"String_Node_Str");
    DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder builder=factory.newDocumentBuilder();
    Document xdoc=builder.parse(new CSFileInputStream(examplePath));
    XmlGenerator xmlgen=new XmlGenerator();
    File dst=new File(page.getFolders().dstDir + exampleName);
    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);
  page.getEpub().registerFile(title + "String_Node_Str","String_Node_Str" + exampleName,EPubManager.XHTML_TYPE);
  TextFile.stringToFile(src,page.getFolders().dstDir + title + "String_Node_Str");
  page.getEpub().registerFile(title + "String_Node_Str","String_Node_Str" + exampleName,EPubManager.XHTML_TYPE);
  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.processPageIncludes(title + "String_Node_Str",html,master == null ? "String_Node_Str" : "String_Node_Str" + master,null);
  TextFile.stringToFile(html,page.getFolders().dstDir + title + "String_Node_Str");
  page.getEpub().registerFile(title + "String_Node_Str","String_Node_Str",EPubManager.XHTML_TYPE);
  jsonToXhtml(title + "String_Node_Str","String_Node_Str" + profile.metadata("String_Node_Str"),resource2Json(p),master == null ? "String_Node_Str" : "String_Node_Str" + master);
  tmp.delete();
  return p;
}