Program: 81160
Project: 81160
Buggy source:
/** 
 * <p>Find an accessible method that matches the given name and has compatible parameters. Compatible parameters mean that every method parameter is assignable from  the given parameters. In other words, it finds a method with the given name  that will take the parameters given.<p> <p>This method is slightly undeterminstic since it loops  through methods names and return the first matching method.</p> <p>This method is used by   {@link #invokeMethod(Object object,String methodName,Object[] args,Class[] parameterTypes)}. <p>This method can match primitive parameter by passing in wrapper classes. For example, a <code>Boolean</code> will match a primitive <code>boolean</code> parameter.
 * @param clazz find method in this class
 * @param methodName find method with this name
 * @param parameterTypes find method with compatible parameters 
 * @return The accessible method
 */
public static Method getMatchingAccessibleMethod(Class clazz,String methodName,Class[] parameterTypes){
  MethodDescriptor md=new MethodDescriptor(clazz,methodName,parameterTypes,false);
  try {
    Method method=getCachedMethod(md);
    if (method != null) {
      return method;
    }
    method=clazz.getMethod(methodName,parameterTypes);
    setMethodAccessible(method);
    cacheMethod(md,method);
    return method;
  }
 catch (  NoSuchMethodException e) {
  }
  int paramSize=parameterTypes.length;
  Method bestMatch=null;
  Method[] methods=clazz.getMethods();
  float bestMatchCost=Float.MAX_VALUE;
  float myCost=Float.MAX_VALUE;
  for (int i=0, size=methods.length; i < size; i++) {
    if (methods[i].getName().equals(methodName)) {
      Class[] methodsParams=methods[i].getParameterTypes();
      int methodParamSize=methodsParams.length;
      if (methodParamSize == paramSize) {
        boolean match=true;
        for (int n=0; n < methodParamSize; n++) {
          if (!isAssignmentCompatible(methodsParams[n],parameterTypes[n])) {
            match=false;
            break;
          }
        }
        if (match) {
          Method method=getAccessibleMethod(clazz,methods[i]);
          if (method != null) {
            setMethodAccessible(method);
            myCost=getTotalTransformationCost(parameterTypes,method.getParameterTypes());
            if (myCost < bestMatchCost) {
              bestMatch=method;
              bestMatchCost=myCost;
            }
          }
        }
      }
    }
  }
  if (bestMatch != null) {
    cacheMethod(md,bestMatch);
  }
 else {
  }
  return bestMatch;
}

Fixed version (ground truth):
/** 
 * <p>Find an accessible method that matches the given name and has compatible parameters. Compatible parameters mean that every method parameter is assignable from  the given parameters. In other words, it finds a method with the given name  that will take the parameters given.<p> <p>This method is slightly undeterminstic since it loops  through methods names and return the first matching method.</p> <p>This method is used by   {@link #invokeMethod(Object object,String methodName,Object[] args,Class[] parameterTypes)}. <p>This method can match primitive parameter by passing in wrapper classes. For example, a <code>Boolean</code> will match a primitive <code>boolean</code> parameter.
 * @param clazz find method in this class
 * @param methodName find method with this name
 * @param parameterTypes find method with compatible parameters 
 * @return The accessible method
 */
public static Method getMatchingAccessibleMethod(Class clazz,String methodName,Class[] parameterTypes){
  MethodDescriptor md=new MethodDescriptor(clazz,methodName,parameterTypes,false);
  try {
    Method method=getCachedMethod(md);
    if (method != null) {
      return method;
    }
    method=clazz.getMethod(methodName,parameterTypes);
    setMethodAccessible(method);
    cacheMethod(md,method);
    return method;
  }
 catch (  NoSuchMethodException e) {
  }
  int paramSize=parameterTypes.length;
  Method bestMatch=null;
  Method[] methods=clazz.getMethods();
  float bestMatchCost=Float.MAX_VALUE;
  float myCost=Float.MAX_VALUE;
  for (int i=0, size=methods.length; i < size; i++) {
    if (methods[i].getName().equals(methodName)) {
      Class[] methodsParams=methods[i].getParameterTypes();
      int methodParamSize=methodsParams.length;
      if (methodParamSize == paramSize) {
        boolean match=true;
        for (int n=0; n < methodParamSize; n++) {
          if (!isAssignmentCompatible(methodsParams[n],parameterTypes[n])) {
            match=false;
            break;
          }
        }
        if (match) {
          Method method=getAccessibleMethod(clazz,methods[i]);
          if (method != null) {
            setMethodAccessible(method);
            myCost=getTotalTransformationCost(parameterTypes,method.getParameterTypes());
            if (myCost < bestMatchCost) {
              bestMatch=method;
              bestMatchCost=myCost;
            }
          }
        }
      }
    }
  }
  if (bestMatch != null) {
    cacheMethod(md,bestMatch);
  }
  return bestMatch;
}