Program: 74979
Project: 74979
Buggy source:
/** 
 * Traverse the directory tree recursively and generate .moml index files.
 * @param inputSuffix Suffix for the input files to look for.
 * @param indexFilename Name of the index file to look for.
 * @param outputFilename Name of the index file to generate.
 * @param root Root dir of the input files.
 * @param currentDir The current directory in this call to proc().
 * @exception Exception If internal error (duplicate file foundor invalid currentDir name.
 */
public static void proc(final String inputSuffix,final String indexFilename,String outputFilename,String root,String currentDir) throws Exception {
  if (File.separator.equals("String_Node_Str")) {
    currentDir=currentDir.replace('\\','/');
  }
  File dir=new File(currentDir);
  FileFilter filterForDirs=new FileFilter(){
    public boolean accept(    File file){
      return file.isDirectory();
    }
  }
;
  File[] children=dir.listFiles(filterForDirs);
  for (int i=0; i < children.length; i++) {
    proc(inputSuffix,indexFilename,indexFilename,root,children[i].toString());
  }
  FilenameFilter filterForIndexFilename=new FilenameFilter(){
    public boolean accept(    File dir,    String name){
      return name.equals(indexFilename);
    }
  }
;
  ArrayList indexFiles=new ArrayList();
  for (int i=0; i < children.length; i++) {
    File[] grandchildren=children[i].listFiles(filterForIndexFilename);
    if (grandchildren.length == 1) {
      String indexFile=grandchildren[0].toString();
      if (File.separator.equals("String_Node_Str")) {
        indexFile=indexFile.replace('\\','/');
      }
      String[] indexFileSubNames=indexFile.split("String_Node_Str");
      if (indexFileSubNames.length < 2) {
        throw new Exception("String_Node_Str");
      }
 else {
        String newIndexFileName=indexFileSubNames[indexFileSubNames.length - 2] + "String_Node_Str" + indexFileSubNames[indexFileSubNames.length - 1];
        indexFiles.add(newIndexFileName);
      }
    }
 else {
      if (grandchildren.length > 1) {
        throw new Exception("String_Node_Str" + indexFilename + "String_Node_Str"+ children[i]);
      }
    }
  }
  FilenameFilter filterForInputSuffix=new FilenameFilter(){
    public boolean accept(    File dir,    String name){
      return name.endsWith(inputSuffix) && !name.equals(indexFilename);
    }
  }
;
  String[] ncFiles=dir.list(filterForInputSuffix);
  String[] components={};
  if (ncFiles.length > 0) {
    components=new String[ncFiles.length];
    for (int i=0; i < ncFiles.length; i++) {
      String shortpath=currentDir.replaceFirst("String_Node_Str" + root,"String_Node_Str");
      shortpath=shortpath.replaceFirst("String_Node_Str" + "String_Node_Str","String_Node_Str");
      shortpath=shortpath + "String_Node_Str" + ncFiles[i];
      shortpath=shortpath.replaceFirst(inputSuffix + "String_Node_Str","String_Node_Str");
      components[i]=shortpath;
    }
  }
  String[] currentDirSubnames=null;
  try {
    currentDirSubnames=currentDir.split("String_Node_Str");
    if (currentDirSubnames.length < 1) {
      throw new Exception("String_Node_Str" + currentDir);
    }
  }
 catch (  java.util.regex.PatternSyntaxException ex) {
    throw new Exception("String_Node_Str" + currentDir + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str",ex);
  }
  String libraryName=currentDirSubnames[currentDirSubnames.length - 1];
  String fullOutputFilename=currentDir + "String_Node_Str" + outputFilename;
  String[] stringArrayType={};
  MoMLLib.generateIndex(components,(String[])indexFiles.toArray(stringArrayType),libraryName,fullOutputFilename);
}

Fixed version (ground truth):
/** 
 * Traverse the directory tree recursively and generate .moml index files.
 * @param inputSuffix Suffix for the input files to look for.
 * @param indexFilename Name of the index file to look for andgenerate for non-top level.
 * @param indexFilenameTopLevel Name of the top-level index fileto generate.
 * @param toplevel True if this is the top-level call to proc().
 * @param root Root dir of the input files.
 * @param currentDir The current directory in this call to proc().
 * @exception Exception If internal error (duplicate file foundor invalid currentDir name.
 */
public static void proc(final String inputSuffix,final String indexFilename,final String indexFilenameTopLevel,boolean toplevel,String root,String currentDir) throws Exception {
  if (File.separator.equals("String_Node_Str")) {
    currentDir=currentDir.replace('\\','/');
  }
  File dir=new File(currentDir);
  FileFilter filterForDirs=new FileFilter(){
    public boolean accept(    File file){
      return file.isDirectory();
    }
  }
;
  File[] children=dir.listFiles(filterForDirs);
  for (int i=0; i < children.length; i++) {
    proc(inputSuffix,indexFilename,indexFilenameTopLevel,false,root,children[i].toString());
  }
  FilenameFilter filterForIndexFilename=new FilenameFilter(){
    public boolean accept(    File dir,    String name){
      return name.equals(indexFilename);
    }
  }
;
  ArrayList indexFiles=new ArrayList();
  for (int i=0; i < children.length; i++) {
    File[] grandchildren=children[i].listFiles(filterForIndexFilename);
    if (grandchildren.length == 1) {
      String indexFile=grandchildren[0].toString();
      if (File.separator.equals("String_Node_Str")) {
        indexFile=indexFile.replace('\\','/');
      }
      String[] indexFileSubNames=indexFile.split("String_Node_Str");
      if (indexFileSubNames.length < 2) {
        throw new Exception("String_Node_Str");
      }
 else {
        String newIndexFileName=indexFileSubNames[indexFileSubNames.length - 2] + "String_Node_Str" + indexFileSubNames[indexFileSubNames.length - 1];
        indexFiles.add(newIndexFileName);
      }
    }
 else {
      if (grandchildren.length > 1) {
        throw new Exception("String_Node_Str" + indexFilename + "String_Node_Str"+ children[i]);
      }
    }
  }
  FilenameFilter filterForInputSuffix=new FilenameFilter(){
    public boolean accept(    File dir,    String name){
      return name.endsWith(inputSuffix) && !name.equals(indexFilename) && !name.equals(indexFilenameTopLevel);
    }
  }
;
  String[] ncFiles=dir.list(filterForInputSuffix);
  String[] components={};
  if (ncFiles.length > 0) {
    components=new String[ncFiles.length];
    for (int i=0; i < ncFiles.length; i++) {
      String shortpath=currentDir.replaceFirst("String_Node_Str" + root,"String_Node_Str");
      shortpath=shortpath.replaceFirst("String_Node_Str" + "String_Node_Str","String_Node_Str");
      if (shortpath.equals("String_Node_Str")) {
        shortpath=ncFiles[i];
      }
 else {
        shortpath=shortpath + "String_Node_Str" + ncFiles[i];
      }
      shortpath=shortpath.replaceFirst(inputSuffix + "String_Node_Str","String_Node_Str");
      components[i]=shortpath;
    }
  }
  String[] currentDirSubnames=null;
  try {
    currentDirSubnames=currentDir.split("String_Node_Str");
    if (currentDirSubnames.length < 1) {
      throw new Exception("String_Node_Str" + currentDir);
    }
  }
 catch (  java.util.regex.PatternSyntaxException ex) {
    throw new Exception("String_Node_Str" + currentDir + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str",ex);
  }
  String libraryName=currentDirSubnames[currentDirSubnames.length - 1];
  String fullOutputFilename;
  if (toplevel) {
    fullOutputFilename=currentDir + "String_Node_Str" + indexFilenameTopLevel;
  }
 else {
    fullOutputFilename=currentDir + "String_Node_Str" + indexFilename;
  }
  String[] stringArrayType={};
  MoMLLib.generateIndex(components,(String[])indexFiles.toArray(stringArrayType),libraryName,fullOutputFilename);
}