Program: 74897
Project: 74897
Buggy source:
/** 
 * Get the shortest possible name of the a class. If there is no conflict, the class is first imported, and only the simple class is returned; otherwise, the its full name is returned.
 * @param name The full class name. It must not be the name of an arraytype.
 * @param loader The class loader used to test importation conflicts.
 * @param root The root of the AST. If there is no conflict and the classhas not been imported yet, a new  {@link ImportDeclaration} is added toit.
 * @return The shortest possible class name.
 */
private static String _getNonarrayClassName(String name,TypeAnalyzerState state,CompilationUnit root){
  LocalClassLoader loader=state.getClassLoader();
  int lastDot=name.lastIndexOf('.');
  String packageName=(lastDot == -1) ? "String_Node_Str" : name.substring(0,lastDot);
  String className=name.substring(lastDot + 1);
  String simpleName;
  int lastSeparator=lastIndexOf(name,new char[]{'.','$'});
  if (lastSeparator == -1) {
    return name;
  }
 else {
    simpleName=name.substring(lastSeparator + 1);
  }
  String currentClassName=state.getCurrentClass().getName();
  if (name.equals(currentClassName)) {
    return simpleName;
  }
 else {
    int dollarPos=currentClassName.length();
    while (dollarPos >= 0) {
      String baseName=currentClassName.substring(0,dollarPos) + "String_Node_Str";
      if (name.startsWith(baseName)) {
        return name.substring(baseName.length());
      }
      dollarPos=currentClassName.lastIndexOf('$',dollarPos - 1);
    }
  }
  Iterator importedClasses=loader.getImportedClasses().iterator();
  while (importedClasses.hasNext()) {
    ClassImport importedClass=(ClassImport)importedClasses.next();
    if (importedClass.getPackageName().equals(packageName) && importedClass.getClassName().equals(className)) {
      return simpleName;
    }
 else {
      String importedName=importedClass.getClassName();
      int lastDollar=importedName.lastIndexOf('$');
      if ((lastDollar == -1) && importedName.equals(simpleName)) {
        return name;
      }
 else       if ((lastDollar >= 0) && importedName.substring(lastDollar + 1).equals(simpleName)) {
        return name;
      }
    }
  }
  Iterator importedPackages=loader.getImportedPackages().iterator();
  while (importedPackages.hasNext()) {
    String importedPackage=(String)importedPackages.next();
    if (importedPackage.equals(packageName)) {
      return simpleName;
    }
 else {
      try {
        loader.loadClass(importedPackage + "String_Node_Str" + simpleName);
        return name;
      }
 catch (      ClassNotFoundException e) {
      }
    }
  }
  AST ast=root.getAST();
  ImportDeclaration declaration=ast.newImportDeclaration();
  declaration.setName(createName(ast,name));
  root.imports().add(declaration);
  loader.importClass(name);
  return simpleName;
}

Fixed version (ground truth):
/** 
 * Get the shortest possible name of the a class. If there is no conflict, the class is first imported, and only the simple class is returned; otherwise, the its full name is returned.
 * @param name The full class name. It must not be the name of an arraytype.
 * @param state The state of the type analyzer.
 * @param root The root of the AST. If there is no conflict and the classhas not been imported yet, a new  {@link ImportDeclaration} is added toit.
 * @return The shortest possible class name.
 */
private static String _getNonarrayClassName(String name,TypeAnalyzerState state,CompilationUnit root){
  LocalClassLoader loader=state.getClassLoader();
  int lastDot=name.lastIndexOf('.');
  String packageName=(lastDot == -1) ? "String_Node_Str" : name.substring(0,lastDot);
  String className=name.substring(lastDot + 1);
  String simpleName;
  int lastSeparator=lastIndexOf(name,new char[]{'.','$'});
  if (lastSeparator == -1) {
    return name;
  }
 else {
    simpleName=name.substring(lastSeparator + 1);
  }
  String currentClassName=state.getCurrentClass().getName();
  if (name.equals(currentClassName)) {
    return simpleName;
  }
 else {
    int dollarPos=currentClassName.length();
    while (dollarPos >= 0) {
      String baseName=currentClassName.substring(0,dollarPos) + "String_Node_Str";
      if (name.startsWith(baseName)) {
        return name.substring(baseName.length());
      }
      dollarPos=currentClassName.lastIndexOf('$',dollarPos - 1);
    }
  }
  Iterator importedClasses=loader.getImportedClasses().iterator();
  while (importedClasses.hasNext()) {
    ClassImport importedClass=(ClassImport)importedClasses.next();
    if (importedClass.getPackageName().equals(packageName) && importedClass.getClassName().equals(className)) {
      return simpleName;
    }
 else {
      String importedName=importedClass.getClassName();
      int lastDollar=importedName.lastIndexOf('$');
      if ((lastDollar == -1) && importedName.equals(simpleName)) {
        return name;
      }
 else       if ((lastDollar >= 0) && importedName.substring(lastDollar + 1).equals(simpleName)) {
        return name;
      }
    }
  }
  Iterator importedPackages=loader.getImportedPackages().iterator();
  while (importedPackages.hasNext()) {
    String importedPackage=(String)importedPackages.next();
    if (importedPackage.equals(packageName)) {
      return simpleName;
    }
 else {
      try {
        loader.loadClass(importedPackage + "String_Node_Str" + simpleName);
        return name;
      }
 catch (      ClassNotFoundException e) {
      }
    }
  }
  AST ast=root.getAST();
  ImportDeclaration declaration=ast.newImportDeclaration();
  declaration.setName(createName(ast,name));
  root.imports().add(declaration);
  loader.importClass(name);
  return simpleName;
}