Program: 74983
Project: 74983
Buggy source:
/** 
 * Generate the .moml index file for the given arguments. Example: <?xml version="1.0"?> <!DOCTYPE plot PUBLIC "-//UC Berkeley//DTD MoML 1//EN" "http://ptolemy.eecs.berkeley.edu/xml/dtd/MoML_1.dtd"> <!--DO NOT EDIT.  This file was generated by ptolemy.domains.ptinyos.util.nc2moml.MoMLLib.  The filename was chosen so that it does not conflict with .nc files of the same name and any other ptII-referenced .moml file in the classpath.--> <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>
 * @param components Array containing the components in shortpath format relative to the root. Example: tos/lib/Counters/Counter
 * @param libraryName Name of this directory.
 * @param indexFiles Array containing the sub-index files inshort path format relative to the outputFile directory. Example: subdir/_TOSIndex.moml
 * @param outputFile The file to generate in long path format.Example: /home/celaine/ptII/vendors/ptinyos/moml/tos/lib/Counters/Counter/index.moml
 * @exception IOException If there is a problem writing files.
 */
public static void generateIndex(String[] components,String[] indexFiles,String libraryName,String outputFile) throws IOException {
  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");
    if (File.separator.equals("String_Node_Str")) {
      indexFiles[i]=indexFiles[i].replace('\\','/');
    }
    input.setAttribute("String_Node_Str",FileUtilities.nameToURL(indexFiles[i],null,null).toString());
    group.addContent(input);
  }
  for (int i=0; i < components.length; i++) {
    try {
      String c=components[i];
      if (File.separator.equals("String_Node_Str")) {
        c=c.replace('\\','/');
      }
      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);
    }
 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);
  FileOutputStream out=null;
  try {
    if (outputFile != null) {
      out=new FileOutputStream(outputFile);
    }
    if (out != null) {
      serializer.output(doc,out);
    }
 else {
      serializer.output(doc,System.out);
    }
  }
 catch (  IOException ex) {
    IOException ioException=new IOException("String_Node_Str" + outputFile + "String_Node_Str");
    ioException.initCause(ex);
    throw ioException;
  }
 finally {
    if (out != null) {
      try {
        out.close();
      }
 catch (      IOException ex) {
        System.err.println("String_Node_Str" + outputFile + "String_Node_Str"+ ex);
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Generate the .moml index file for the given arguments. Example: <?xml version="1.0"?> <!DOCTYPE plot PUBLIC "-//UC Berkeley//DTD MoML 1//EN" "http://ptolemy.eecs.berkeley.edu/xml/dtd/MoML_1.dtd"> <!--DO NOT EDIT.  This file was generated by ptolemy.domains.ptinyos.util.nc2moml.MoMLLib.  The filename was chosen so that it does not conflict with .nc files of the same name and any other ptII-referenced .moml file in the classpath.--> <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>
 * @param components Array containing the components in shortpath format relative to the root. Example: tos/lib/Counters/Counter
 * @param libraryName Name of this directory.
 * @param indexFiles Array containing the sub-index files inshort path format relative to the outputFile directory. Example: subdir/_TOSIndex.moml
 * @param outputFile The file to generate in long path format.Example: /home/celaine/ptII/vendors/ptinyos/moml/tos/lib/Counters/Counter/index.moml
 * @exception IOException If there is a problem writing files.
 */
public static void generateIndex(String[] components,String[] indexFiles,String libraryName,String outputFile) throws IOException {
  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");
    if (File.separator.equals("String_Node_Str")) {
      indexFiles[i]=indexFiles[i].replace('\\','/');
    }
    try {
      input.setAttribute("String_Node_Str",FileUtilities.nameToURL(indexFiles[i],null,null).toString());
    }
 catch (    MalformedURLException e) {
      input.setAttribute("String_Node_Str",indexFiles[i]);
    }
    group.addContent(input);
  }
  for (int i=0; i < components.length; i++) {
    String c=components[i];
    if (File.separator.equals("String_Node_Str")) {
      c=c.replace('\\','/');
    }
    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);
  FileOutputStream out=null;
  try {
    if (outputFile != null) {
      out=new FileOutputStream(outputFile);
    }
    if (out != null) {
      serializer.output(doc,out);
    }
 else {
      serializer.output(doc,System.out);
    }
  }
 catch (  IOException ex) {
    IOException ioException=new IOException("String_Node_Str" + outputFile + "String_Node_Str");
    ioException.initCause(ex);
    throw ioException;
  }
 finally {
    if (out != null) {
      try {
        out.close();
      }
 catch (      IOException ex) {
        System.err.println("String_Node_Str" + outputFile + "String_Node_Str"+ ex);
      }
    }
  }
}