code: @SuppressWarnings("unchecked")
    private static Method findJobMethodToInvoke(
        Class<?> klass, boolean callErrorHandler, Object[] params) {
      Method runMethod = null;
      if (callErrorHandler) {
        if (params.length != 1) {
          throw new RuntimeException(
              "Invalid number of parameters passed to handleException:" + params.length);
        }
        Object parameter = params[0];
        if (parameter == null) {
          throw new RuntimeException("Null parameters passed to handleException:" + params.length);
        }
        Class<? extends Object> parameterClass = parameter.getClass();
        if (!Throwable.class.isAssignableFrom(parameterClass)) {
          throw new RuntimeException("Parameter that is not an exception passed to handleException:"
              + parameterClass.getName());
        }
        Class<? extends Throwable> exceptionClass = (Class<? extends Throwable>) parameterClass;
        do {
          try {
            runMethod = klass.getMethod(
                JobRecord.EXCEPTION_HANDLER_METHOD_NAME, new Class<?>[] {exceptionClass});
            break;
          } catch (NoSuchMethodException e) {
            // Ignore, try parent instead.
          }
          exceptionClass = (Class<? extends Throwable>) exceptionClass.getSuperclass();
        } while (exceptionClass != null);
      } else {
        for (Method method : klass.getMethods()) {
          if ("run".equals(method.getName())) {
            runMethod = method;
            break;
          }
        }
      }
      return runMethod;
    }
docs: Return handleException method (if callErrorHandler is <code>true</code>).
  Otherwise return first run method (order is defined by order of
  {@link Class#getMethods()} is return. <br>
  TODO(user) Consider actually looking for a method with matching
  signature<br>
  TODO(maximf) Consider getting rid of reflection based invocations
  completely.
  
  @param klass Class of the user provided job
  @param callErrorHandler should handleException method be returned instead
  of run
  @param params parameters to be passed to the method to invoke
  @return Either run or handleException method of {@code class}. <code>null
  </code> is returned if @{code callErrorHandler} is <code>true</code>
  and no handleException with matching signature is found.