public static Method findAccessibleMethod(Method method) throws NoSuchMethodException {
  Class<?> type=method.getDeclaringClass();
  if (Modifier.isPublic(type.getModifiers()) && isPackageAccessible(type)) {
    return method;
  }
  if (Modifier.isStatic(method.getModifiers())) {
    throw new NoSuchMethodException("Method '" + method.getName() + "' is not accessible");
  }
  for (  Type generic : type.getGenericInterfaces()) {
    try {
      return findAccessibleMethod(method,generic);
    }
 catch (    NoSuchMethodException exception) {
    }
  }
  return findAccessibleMethod(method,type.getGenericSuperclass());
}

public static Method findAccessibleMethod ( Method method ) throws NoSuchMethodException { Class < ? > type = method . getDeclaringClass ( ) ; if ( Modifier . isPublic ( type . getModifiers ( ) ) && isPackageAccessible ( type ) ) { return method ; } if ( Modifier . isStatic ( method . getModifiers ( ) ) ) { throw new NoSuchMethodException ( "Method '" + method . getName ( ) + "' is not accessible" ) ; } for ( Type generic : type . getGenericInterfaces ( ) ) { try { return findAccessibleMethod ( method , generic ) ; } catch ( NoSuchMethodException exception ) { } } return findAccessibleMethod ( method , type . getGenericSuperclass ( ) ) ; }
finds method that is accessible from public class or interface through class hierarchy .
