Program: 74987
Project: 74987
Buggy source:
/** 
 * components is in short path format relative to root Example: tos/lib/Counters/Counter indexFiles is in short path format relative to dir of outputFile Example: subdir/index.moml outputFile is in long path format Example: /home/celaine/trash/todayoutput2/tos/lib/Counters/Counter/index.moml <?xml version="1.0" standalone="no"?> <!DOCTYPE plot PUBLIC "-//UC Berkeley//DTD MoML 1//EN" "http://ptolemy.eecs.berkeley.edu/xml/dtd/MoML_1.dtd"> <entity name="Counters" class="ptolemy.moml.EntityLibrary"> <configure> <?moml <group> <entity name="Counter" class="tos.lib.Counters.Counter"/> <entity name="IntToLeds" class="tos.lib.Counters.IntToLeds"/> <entity name="IntToLedsM" class="tos.lib.Counters.IntToLedsM"/> <entity name="IntToRfm" class="tos.lib.Counters.IntToRfm"/> <entity name="IntToRfmM" class="tos.lib.Counters.IntToRfmM"/> <entity name="RfmToInt" class="tos.lib.Counters.RfmToInt"/> <entity name="RfmToIntM" class="tos.lib.Counters.RfmToIntM"/> <entity name="SenseToInt" class="tos.lib.Counters.SenseToInt"/> </group> ?> </configure> </entity>
 */
public static void generateIndex(String[] components,String[] indexFiles,String libraryName,String outputFile){
  Element root=new Element("String_Node_Str");
  root.setAttribute("String_Node_Str",libraryName);
  root.setAttribute("String_Node_Str","String_Node_Str");
  Element configure=new Element("String_Node_Str");
  root.addContent(configure);
  DocType plot=new DocType("String_Node_Str","String_Node_Str","String_Node_Str");
  Document doc=new Document();
  doc.addContent(new Comment("String_Node_Str"));
  doc.setRootElement(root);
  doc.setDocType(plot);
  Element group=new Element("String_Node_Str");
  for (int i=0; i < indexFiles.length; i++) {
    Element input=new Element("String_Node_Str");
    input.setAttribute("String_Node_Str",indexFiles[i]);
    group.addContent(input);
  }
  for (int i=0; i < components.length; i++) {
    String c=components[i];
    String[] subNames=c.split("String_Node_Str");
    String componentName=subNames[subNames.length - 1];
    String className=c.replaceAll("String_Node_Str","String_Node_Str");
    Element entity=new Element("String_Node_Str");
    entity.setAttribute("String_Node_Str",componentName);
    entity.setAttribute("String_Node_Str",className);
    group.addContent(entity);
  }
  XMLOutputter serializer=new XMLOutputter(Format.getPrettyFormat());
  Format format=serializer.getFormat();
  format.setOmitEncoding(true);
  format.setLineSeparator("String_Node_Str");
  serializer.setFormat(format);
  ProcessingInstruction moml=new ProcessingInstruction("String_Node_Str","String_Node_Str" + serializer.outputString(group) + "String_Node_Str");
  configure.addContent(moml);
  try {
    FileOutputStream out=null;
    if (outputFile != null) {
      out=new FileOutputStream(outputFile);
    }
    if (out != null) {
      serializer.output(doc,out);
      out.flush();
      out.close();
    }
 else {
      serializer.output(doc,System.out);
    }
  }
 catch (  IOException e) {
    System.err.println(e);
  }
}

Fixed version (ground truth):
/** 
 * components is in short path format relative to root Example: tos/lib/Counters/Counter indexFiles is in short path format relative to dir of outputFile Example: subdir/index.moml outputFile is in long path format Example: /home/celaine/trash/todayoutput2/tos/lib/Counters/Counter/index.moml <?xml version="1.0" standalone="no"?> <!DOCTYPE plot PUBLIC "-//UC Berkeley//DTD MoML 1//EN" "http://ptolemy.eecs.berkeley.edu/xml/dtd/MoML_1.dtd"> <entity name="Counters" class="ptolemy.moml.EntityLibrary"> <configure> <?moml <group> <entity name="Counter" class="tos.lib.Counters.Counter"/> <entity name="IntToLeds" class="tos.lib.Counters.IntToLeds"/> <entity name="IntToLedsM" class="tos.lib.Counters.IntToLedsM"/> <entity name="IntToRfm" class="tos.lib.Counters.IntToRfm"/> <entity name="IntToRfmM" class="tos.lib.Counters.IntToRfmM"/> <entity name="RfmToInt" class="tos.lib.Counters.RfmToInt"/> <entity name="RfmToIntM" class="tos.lib.Counters.RfmToIntM"/> <entity name="SenseToInt" class="tos.lib.Counters.SenseToInt"/> </group> ?> </configure> </entity>
 */
public static void generateIndex(String[] components,String[] indexFiles,String libraryName,String outputFile){
  Element root=new Element("String_Node_Str");
  root.setAttribute("String_Node_Str",libraryName);
  root.setAttribute("String_Node_Str","String_Node_Str");
  Element configure=new Element("String_Node_Str");
  root.addContent(configure);
  DocType plot=new DocType("String_Node_Str","String_Node_Str","String_Node_Str");
  Document doc=new Document();
  String comment="String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str";
  doc.addContent(new Comment(comment));
  doc.setRootElement(root);
  doc.setDocType(plot);
  Element group=new Element("String_Node_Str");
  for (int i=0; i < indexFiles.length; i++) {
    Element input=new Element("String_Node_Str");
    input.setAttribute("String_Node_Str",indexFiles[i]);
    group.addContent(input);
  }
  for (int i=0; i < components.length; i++) {
    try {
      String c=components[i];
      String[] subNames=c.split(File.separator);
      String componentName=subNames[subNames.length - 1];
      String className=c.replaceAll(File.separator,"String_Node_Str");
      Element entity=new Element("String_Node_Str");
      entity.setAttribute("String_Node_Str",componentName);
      entity.setAttribute("String_Node_Str",className);
      group.addContent(entity);
    }
 catch (    PatternSyntaxException e) {
      System.err.println("String_Node_Str" + e);
      e.printStackTrace();
    }
  }
  XMLOutputter serializer=new XMLOutputter(Format.getPrettyFormat());
  Format format=serializer.getFormat();
  format.setOmitEncoding(true);
  format.setLineSeparator("String_Node_Str");
  serializer.setFormat(format);
  ProcessingInstruction moml=new ProcessingInstruction("String_Node_Str","String_Node_Str" + serializer.outputString(group) + "String_Node_Str");
  configure.addContent(moml);
  try {
    FileOutputStream out=null;
    if (outputFile != null) {
      out=new FileOutputStream(outputFile);
    }
    if (out != null) {
      serializer.output(doc,out);
      out.flush();
      out.close();
    }
 else {
      serializer.output(doc,System.out);
    }
  }
 catch (  IOException e) {
    System.err.println("String_Node_Str" + e);
  }
}