Program: 73362
Project: 73362
Buggy source:
/** 
 * Generate the index files.
 * @param classesFileName The name of the file that contains thedot separated class names - one class per line. This file is usually called allActors.txt, which is generated by running the $PTII/doc/doclets/PtDoc doclet.  For example, see $PTII/doc/codeDoc/allActors.txt
 * @param modelsFileName The name of the file that contains theurls that point to the models to be parsed, one model per line.  This file is usually called models.txt and is generated by running ptolemy.actor.gui.HTMLAbout.
 * @param outputDirectory Directory in which to write index files.The files generated have the name <i>actorName<i>idx.htm, where <i>actorName</i> is the name of the actor.  Typically, the value for this parameter is doc/codeDoc.
 * @exception Exception If there is a problem reading or writinga file.
 */
public static void generateActorIndex(String classesFileName,String modelsFileName,String outputDirectory) throws Exception {
  HashMap classesToBeIndexed=new HashMap();
  BufferedReader classesReader=null;
  BufferedReader modelReader=null;
  try {
    classesReader=new BufferedReader(new FileReader(classesFileName));
    String className;
    while ((className=classesReader.readLine()) != null) {
      System.out.println("String_Node_Str" + className);
      classesToBeIndexed.put(className,new HashSet());
    }
    modelReader=new BufferedReader(new FileReader(modelsFileName));
    String modelName;
    MoMLParser parser=new MoMLParser();
    MoMLParser.setMoMLFilters(BackwardCompatibility.allFilters());
    NamedObjClassesSeen namedObjClassesSeen=new NamedObjClassesSeen(classesToBeIndexed);
    MoMLParser.addMoMLFilter(namedObjClassesSeen);
    RemoveGraphicalClasses removeGraphicalClasses=new RemoveGraphicalClasses();
    removeGraphicalClasses.setRemoveGR(true);
    MoMLParser.addMoMLFilter(removeGraphicalClasses);
    while ((modelName=modelReader.readLine()) != null) {
      namedObjClassesSeen.reset(modelName);
      try {
        URL modelURL=FileUtilities.nameToURL(modelName,null,null);
        System.out.println("String_Node_Str" + modelURL);
        parser.reset();
        parser.parse(null,modelURL);
      }
 catch (      Exception ex) {
        System.err.println("String_Node_Str" + modelName);
        ex.printStackTrace();
      }
    }
  }
  finally {
    if (classesReader != null) {
      try {
        classesReader.close();
      }
 catch (      Exception ex) {
      }
    }
    if (modelReader != null) {
      try {
        modelReader.close();
      }
 catch (      Exception ex) {
      }
    }
  }
  Iterator classes=classesToBeIndexed.entrySet().iterator();
  while (classes.hasNext()) {
    Map.Entry entry=(Map.Entry)classes.next();
    String actorClassName=(String)entry.getKey();
    if (((Set)entry.getValue()).size() == 0) {
      continue;
    }
    BufferedWriter writer=null;
    try {
      String outputFileName=outputDirectory + File.separator + actorClassName.replace('.',File.separatorChar)+ "String_Node_Str";
      String canonicalOutputFileName=new File(outputFileName).getCanonicalPath().replace('\\','/');
      String ptII=null;
      try {
        ptII=new URI(StringUtilities.getProperty("String_Node_Str")).normalize().getPath();
        ptII=new File(ptII).getCanonicalPath().replace('\\','/');
      }
 catch (      URISyntaxException ex) {
        throw new InternalErrorException(null,ex,"String_Node_Str" + ptII);
      }
      if (ptII.length() == 0) {
        throw new InternalErrorException("String_Node_Str" + "String_Node_Str");
      }
      String relativePath="String_Node_Str";
      if (canonicalOutputFileName.startsWith(ptII)) {
        String relativeOutputFileName=StringUtilities.substitute(canonicalOutputFileName,ptII,"String_Node_Str");
        StringBuffer relativePathBuffer=new StringBuffer();
        int index=0;
        while (relativeOutputFileName.indexOf('/',index) != -1) {
          index=relativeOutputFileName.indexOf('/',index) + 1;
          relativePathBuffer.append("String_Node_Str");
        }
        relativePath=relativePathBuffer.toString();
        relativePath=relativePath.substring(0,relativePath.length() - 3);
      }
      File outputDirectoryFile=new File(new File(outputFileName).getParent());
      if (!outputDirectoryFile.exists()) {
        System.out.println("String_Node_Str" + outputDirectoryFile);
        if (!outputDirectoryFile.mkdirs()) {
          throw new IOException("String_Node_Str" + outputDirectoryFile + "String_Node_Str");
        }
      }
      System.out.println("String_Node_Str" + outputFileName);
      writer=new BufferedWriter(new FileWriter(outputFileName));
      writer.write("String_Node_Str" + actorClassName + "String_Node_Str"+ "String_Node_Str"+ relativePath+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ actorClassName+ "String_Node_Str"+ "String_Node_Str"+ actorClassName+ "String_Node_Str");
      Iterator models=((Set)entry.getValue()).iterator();
      while (models.hasNext()) {
        String model=(String)models.next();
        if (model.startsWith("String_Node_Str")) {
          model=model.substring(11);
        }
        writer.write("String_Node_Str" + relativePath + model+ "String_Node_Str"+ model+ "String_Node_Str");
      }
      writer.write("String_Node_Str");
    }
  finally {
      if (writer != null) {
        writer.close();
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Generate the index files.
 * @param classesFileName The name of the file that contains thedot separated class names - one class per line. This file is usually called allActors.txt, which is generated by running the $PTII/doc/doclets/PtDoc doclet.  For example, see $PTII/doc/codeDoc/allActors.txt
 * @param modelsFileName The name of the file that contains theurls that point to the models to be parsed, one model per line.  This file is usually called models.txt and is generated by running ptolemy.actor.gui.HTMLAbout.
 * @param outputDirectory Directory in which to write index files.The files generated have the name <i>actorName<i>idx.htm, where <i>actorName</i> is the name of the actor.  Typically, the value for this parameter is doc/codeDoc.
 * @exception Exception If there is a problem reading or writinga file.
 */
public static void generateActorIndex(String classesFileName,String modelsFileName,String outputDirectory) throws Exception {
  HashMap classesToBeIndexed=new HashMap();
  BufferedReader classesReader=null;
  BufferedReader modelReader=null;
  try {
    classesReader=new BufferedReader(new FileReader(classesFileName));
    String className;
    while ((className=classesReader.readLine()) != null) {
      System.out.println("String_Node_Str" + className);
      classesToBeIndexed.put(className,new HashSet());
    }
    modelReader=new BufferedReader(new FileReader(modelsFileName));
    String modelName;
    MoMLParser parser=new MoMLParser();
    MoMLParser.setMoMLFilters(BackwardCompatibility.allFilters());
    NamedObjClassesSeen namedObjClassesSeen=new NamedObjClassesSeen(classesToBeIndexed);
    MoMLParser.addMoMLFilter(namedObjClassesSeen);
    RemoveGraphicalClasses removeGraphicalClasses=new RemoveGraphicalClasses();
    removeGraphicalClasses.setRemoveGR(true);
    MoMLParser.addMoMLFilter(removeGraphicalClasses);
    while ((modelName=modelReader.readLine()) != null) {
      namedObjClassesSeen.reset(modelName);
      try {
        URL modelURL=FileUtilities.nameToURL(modelName,null,null);
        System.out.println("String_Node_Str" + modelURL);
        parser.reset();
        parser.parse(null,modelURL);
      }
 catch (      Exception ex) {
        System.err.println("String_Node_Str" + modelName);
        ex.printStackTrace();
      }
    }
  }
  finally {
    if (classesReader != null) {
      try {
        classesReader.close();
      }
 catch (      IOException ex) {
        System.out.println("String_Node_Str" + classesReader + "String_Node_Str"+ ex);
      }
    }
    if (modelReader != null) {
      try {
        modelReader.close();
      }
 catch (      IOException ex) {
        System.out.println("String_Node_Str" + modelReader + "String_Node_Str"+ ex);
      }
    }
  }
  Iterator classes=classesToBeIndexed.entrySet().iterator();
  while (classes.hasNext()) {
    Map.Entry entry=(Map.Entry)classes.next();
    String actorClassName=(String)entry.getKey();
    if (((Set)entry.getValue()).size() == 0) {
      continue;
    }
    BufferedWriter writer=null;
    try {
      String outputFileName=outputDirectory + File.separator + actorClassName.replace('.',File.separatorChar)+ "String_Node_Str";
      String canonicalOutputFileName=new File(outputFileName).getCanonicalPath().replace('\\','/');
      String ptII=null;
      try {
        ptII=new URI(StringUtilities.getProperty("String_Node_Str")).normalize().getPath();
        ptII=new File(ptII).getCanonicalPath().replace('\\','/');
      }
 catch (      URISyntaxException ex) {
        throw new InternalErrorException(null,ex,"String_Node_Str" + ptII);
      }
      if (ptII == null || ptII.length() == 0) {
        throw new InternalErrorException("String_Node_Str" + "String_Node_Str");
      }
      String relativePath="String_Node_Str";
      if (canonicalOutputFileName.startsWith(ptII)) {
        String relativeOutputFileName=StringUtilities.substitute(canonicalOutputFileName,ptII,"String_Node_Str");
        StringBuffer relativePathBuffer=new StringBuffer();
        int index=0;
        while (relativeOutputFileName.indexOf('/',index) != -1) {
          index=relativeOutputFileName.indexOf('/',index) + 1;
          relativePathBuffer.append("String_Node_Str");
        }
        relativePath=relativePathBuffer.toString();
        relativePath=relativePath.substring(0,relativePath.length() - 3);
      }
      File outputDirectoryFile=new File(new File(outputFileName).getParent());
      if (!outputDirectoryFile.exists()) {
        System.out.println("String_Node_Str" + outputDirectoryFile);
        if (!outputDirectoryFile.mkdirs()) {
          throw new IOException("String_Node_Str" + outputDirectoryFile + "String_Node_Str");
        }
      }
      System.out.println("String_Node_Str" + outputFileName);
      writer=new BufferedWriter(new FileWriter(outputFileName));
      writer.write("String_Node_Str" + actorClassName + "String_Node_Str"+ "String_Node_Str"+ relativePath+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ actorClassName+ "String_Node_Str"+ "String_Node_Str"+ actorClassName+ "String_Node_Str");
      Iterator models=((Set)entry.getValue()).iterator();
      while (models.hasNext()) {
        String model=(String)models.next();
        if (model.startsWith("String_Node_Str")) {
          model=model.substring(11);
        }
        writer.write("String_Node_Str" + relativePath + model+ "String_Node_Str"+ model+ "String_Node_Str");
      }
      writer.write("String_Node_Str");
    }
  finally {
      if (writer != null) {
        writer.close();
      }
    }
  }
}