Program: 75146
Project: 75146
Buggy source:
/** 
 * Get the type of a method in a class by its name and types of actural arguments. If not found in the class definition, this function also searches the superclasses of that class, as well as the interfaces that the class and its superclasses implement. <p> This function always tries to find the best match if multiple methods with the same name and the same number of arguments are defined in the class and interface hierarchy. This is accomplished by computing the compatibility rating between each pair of formal argument and actural argument, and sum those numbers together.
 * @param c The class from which the method is resolved.
 * @param name The name of the field.
 * @param args The types of actural arguments for a call.
 * @return The return type of the method if found; otherwise,<tt>null</tt>.
 * @see #getFieldType(Class,String)
 * @see Type#compatibility(Type,ClassLoader)
 */
protected Type getMethodType(Class c,String name,Type[] args) throws ASTClassNotFoundException {
  Method[] methods=null;
  int best_compatibility=-1;
  Method best_method=null;
  List workList=new LinkedList();
  Set handledSet=new HashSet();
  workList.add(c);
  while (!workList.isEmpty()) {
    Class topClass=(Class)workList.remove(0);
    methods=topClass.getDeclaredMethods();
    for (int i=0; i < methods.length; i++) {
      Method method=methods[i];
      if (method.getName().equals(name)) {
        Class[] formalParams=method.getParameterTypes();
        if (formalParams.length == args.length) {
          int compatibility=0;
          for (int j=0; j < formalParams.length; j++)           try {
            Type formalType=Type.createType(formalParams[j].getName());
            int comp=args[j].compatibility(formalType,_loader);
            if (comp == -1) {
              compatibility=-1;
              break;
            }
 else             compatibility+=comp;
          }
 catch (          ClassNotFoundException e) {
            throw new ASTClassNotFoundException(args[j].getName());
          }
          if (compatibility == -1)           continue;
 else           if (best_compatibility == -1 || best_compatibility > compatibility) {
            best_compatibility=compatibility;
            best_method=method;
            if (best_compatibility == 0)             break;
          }
        }
      }
    }
    if (best_compatibility == 0)     break;
    handledSet.add(topClass);
    Class[] interfaces=topClass.getInterfaces();
    for (int i=0; i < interfaces.length; i++)     if (!handledSet.contains(interfaces[i]))     workList.add(interfaces[i]);
  }
  if (best_compatibility != -1)   return Type.createType(best_method.getReturnType().getName());
 else   return null;
}

Fixed version (ground truth):
/** 
 * Get the type of a method in a class by its name and types of actural arguments. If not found in the class definition, this function also searches the superclasses of that class, as well as the interfaces that the class and its superclasses implement. <p> This function always tries to find the best match if multiple methods with the same name and the same number of arguments are defined in the class and interface hierarchy. This is accomplished by computing the compatibility rating between each pair of formal argument and actural argument, and sum those numbers together.
 * @param c The class from which the method is resolved.
 * @param name The name of the field.
 * @param args The types of actural arguments for a call.
 * @return The return type of the method if found; otherwise,<tt>null</tt>.
 * @see #getFieldType(Class,String)
 * @see Type#compatibility(Type,ClassLoader)
 */
protected Type getMethodType(Class c,String name,Type[] args) throws ASTClassNotFoundException {
  Method[] methods=null;
  int best_compatibility=-1;
  Method best_method=null;
  List workList=new LinkedList();
  Set handledSet=new HashSet();
  workList.add(c);
  while (!workList.isEmpty()) {
    Class topClass=(Class)workList.remove(0);
    methods=topClass.getDeclaredMethods();
    for (int i=0; i < methods.length; i++) {
      Method method=methods[i];
      if (method.getName().equals(name)) {
        Class[] formalParams=method.getParameterTypes();
        if (formalParams.length == args.length) {
          int compatibility=0;
          for (int j=0; j < formalParams.length; j++)           try {
            Type formalType=Type.createType(formalParams[j].getName());
            int comp=args[j].compatibility(formalType,_loader);
            if (comp == -1) {
              compatibility=-1;
              break;
            }
 else             compatibility+=comp;
          }
 catch (          ClassNotFoundException e) {
            throw new ASTClassNotFoundException(args[j].getName());
          }
          if (compatibility == -1)           continue;
 else           if (best_compatibility == -1 || best_compatibility > compatibility) {
            best_compatibility=compatibility;
            best_method=method;
            if (best_compatibility == 0)             break;
          }
        }
      }
    }
    if (best_compatibility == 0)     break;
    handledSet.add(topClass);
    Class superClass=topClass.getSuperclass();
    if (superClass == null && !topClass.getName().equals("String_Node_Str"))     superClass=Object.class;
    if (superClass != null)     workList.add(superClass);
    Class[] interfaces=topClass.getInterfaces();
    for (int i=0; i < interfaces.length; i++)     if (!handledSet.contains(interfaces[i]))     workList.add(interfaces[i]);
  }
  if (best_compatibility != -1)   return Type.createType(best_method.getReturnType().getName());
 else   return null;
}