Program: 76820
Project: 76820
Buggy source:
/** 
 * Returns a   {@code Method} object that reflects the specified publicmember method of the class or interface represented by this {@code Class} object. The {@code name} parameter is a{@code String} specifying the simple name of the desired method. The{@code parameterTypes} parameter is an array of {@code Class}objects that identify the method's formal parameter types, in declared order. If   {@code parameterTypes} is {@code null}, it is treated as if it were an empty array. <p> If the   {@code name} is "{@code <init>}" or "  {@code <clinit>}" a  {@code NoSuchMethodException} is raised. Otherwise, the method tobe reflected is determined by the algorithm that follows.  Let C be the class or interface represented by this object: <OL> <LI> C is searched for a <I>matching method</I>, as defined below. If a matching method is found, it is reflected.</LI> <LI> If no matching method is found by step 1 then: <OL TYPE="a"> <LI> If C is a class other than  {@code Object}, then this algorithm is invoked recursively on the superclass of C.</LI> <LI> If C is the class   {@code Object}, or if C is an interface, then the superinterfaces of C (if any) are searched for a matching method. If any such method is found, it is reflected.</LI> </OL></LI> </OL> <p> To find a matching method in a class or interface C:&nbsp; If C declares exactly one public method with the specified name and exactly the same formal parameter types, that is the method reflected. If more than one such method is found in C, and one of these methods has a return type that is more specific than any of the others, that method is reflected; otherwise one of the methods is chosen arbitrarily. <p>Note that there may be more than one matching method in a class because while the Java language forbids a class to declare multiple methods with the same signature but different return types, the Java virtual machine does not.  This increased flexibility in the virtual machine can be used to implement various language features.  For example, covariant returns can be implemented with   {@linkplain java.lang.reflect.Method#isBridge bridge methods}; the bridge method and the method being overridden would have the same signature but different return types. <p> If this   {@code Class} object represents an array type, then thismethod does not find the  {@code clone()} method.<p> Static methods declared in superinterfaces of the class or interface represented by this  {@code Class} object are not considered members ofthe class or interface.
 * @param name the name of the method
 * @param parameterTypes the list of parameters
 * @return the {@code Method} object that matches the specified{@code name} and {@code parameterTypes}
 * @throws NoSuchMethodException if a matching method is not foundor if the name is "&lt;init&gt;"or "&lt;clinit&gt;".
 * @throws NullPointerException if {@code name} is {@code null}
 * @throws SecurityException If a security manager, <i>s</i>, is present and the caller's class loader is not the same as or an ancestor of the class loader for the current class and invocation of  {@link SecurityManager#checkPackageAccess s.checkPackageAccess()} denies access to the packageof this class.
 * @jls 8.2 Class Members
 * @jls 8.4 Method Declarations
 * @since 1.1
 */
@CallerSensitive public Method getMethod(String name,Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException {
  checkMemberAccess(Member.PUBLIC,Reflection.getCallerClass(),true);
  Method method=getMethod0(name,parameterTypes,true);
  if (method == null) {
    throw new NoSuchMethodException(getName() + "String_Node_Str" + name+ argumentTypesToString(parameterTypes));
  }
  return method;
}

Fixed version (ground truth):
/** 
 * Returns a   {@code Method} object that reflects the specified publicmember method of the class or interface represented by this {@code Class} object. The {@code name} parameter is a{@code String} specifying the simple name of the desired method. The{@code parameterTypes} parameter is an array of {@code Class}objects that identify the method's formal parameter types, in declared order. If   {@code parameterTypes} is {@code null}, it is treated as if it were an empty array. <p> If this   {@code Class} object represents an array type, then thismethod finds any public method inherited by the array type from {@code Object} except method {@code clone()}. <p> If this   {@code Class} object represents an interface then thismethod does not find any implicitly declared method from {@code Object}. Therefore, if no methods are explicitly declared in this interface or any of its superinterfaces, then this method does not find any method. <p> This method does not find any method with name "  {@code <init>}" or "  {@code <clinit>}". <p> Generally, the method to be reflected is determined by the 4 step algorithm that follows. Let C be the class or interface represented by this   {@code Class} object:<ol> <li> A union of methods is composed of: <ol type="a"> <li> C's declared public instance and static methods as returned by {@link #getDeclaredMethods()} and filtered to include only publicmethods that match given  {@code name} and {@code parameterTypes}</li> <li> If C is a class other than   {@code Object}, then include the result of invoking this algorithm recursively on the superclass of C.</li> <li> Include the results of invoking this algorithm recursively on all direct superinterfaces of C, but include only instance methods.</li> </ol></li> <li> This union is partitioned into subsets of methods with same return type (the selection of methods from step 1 also guarantees that they have the same method name and parameter types).</li> <li> Within each such subset only the most specific methods are selected. Let method M be a method from a set of methods with same VM signature (return type, name, parameter types). M is most specific if there is no such method N != M from the same set, such that N is more specific than M. N is more specific than M if: <ol type="a"> <li> N is declared by a class and M is declared by an interface; or</li> <li> N and M are both declared by classes or both by interfaces and N's declaring type is the same as or a subtype of M's declaring type (clearly, if M's and N's declaring types are the same type, then M and N are the same method).</li> </ol></li> <li> The result of this algorithm is chosen arbitrarily from the methods with most specific return type among all selected methods from step 3. Let R be a return type of a method M from the set of all selected methods from step 3. M is a method with most specific return type if there is no such method N != M from the same set, having return type S != R, such that S is a subtype of R as determined by R.class.  {@link #isAssignableFrom}(S.class). </ol>
 * @apiNote There may be more than one method with matching name andparameter types in a class because while the Java language forbids a class to declare multiple methods with the same signature but different return types, the Java virtual machine does not.  This increased flexibility in the virtual machine can be used to implement various language features.  For example, covariant returns can be implemented with  {@linkplain java.lang.reflect.Method#isBridge bridge methods}; the bridge method and the overriding method would have the same signature but different return types. This method would return the overriding method as it would have a more specific return type.
 * @param name the name of the method
 * @param parameterTypes the list of parameters
 * @return the {@code Method} object that matches the specified{@code name} and {@code parameterTypes}
 * @throws NoSuchMethodException if a matching method is not foundor if the name is "&lt;init&gt;"or "&lt;clinit&gt;".
 * @throws NullPointerException if {@code name} is {@code null}
 * @throws SecurityException If a security manager, <i>s</i>, is present and the caller's class loader is not the same as or an ancestor of the class loader for the current class and invocation of  {@link SecurityManager#checkPackageAccess s.checkPackageAccess()} denies access to the packageof this class.
 * @jls 8.2 Class Members
 * @jls 8.4 Method Declarations
 * @since 1.1
 */
@CallerSensitive public Method getMethod(String name,Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException {
  Objects.requireNonNull(name);
  checkMemberAccess(Member.PUBLIC,Reflection.getCallerClass(),true);
  Method method=getMethod0(name,parameterTypes);
  if (method == null) {
    throw new NoSuchMethodException(getName() + "String_Node_Str" + name+ argumentTypesToString(parameterTypes));
  }
  return getReflectionFactory().copyMethod(method);
}