apache/seatunnel · error · RuntimeException

method invoke failed

Error message

method invoke failed

What it means

This is the generic wrapper error from ReflectionUtils.invoke: any NoSuchMethodException, InvocationTargetException, or IllegalAccessException raised while reflectively invoking the method is rethrown as a RuntimeException with message 'method invoke failed'. The original cause (including the target method's own exception, in the InvocationTargetException case) is attached as the cause. Unlike error 180, the message itself does not say what went wrong, so the cause chain must be inspected.

Source

Thrown at seatunnel-common/src/main/java/org/apache/seatunnel/common/utils/ReflectionUtils.java:105

        }
        return invoke(object, methodName, argTypes, args);
    }

    public static Object invoke(
            Object object, String methodName, Class<?>[] argTypes, Object[] args) {
        try {
            Optional<Method> method = getDeclaredMethod(object.getClass(), methodName, argTypes);
            if (method.isPresent()) {
                method.get().setAccessible(true);
                return method.get().invoke(object, args);
            } else {
                throw new NoSuchMethodException(
                        String.format(
                                "method invoke failed, no such method '%s' in '%s'",
                                methodName, object.getClass()));
            }
        } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
            throw new RuntimeException("method invoke failed", e);
        }
    }
}

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Log/inspect e.getCause(): for InvocationTargetException the real failure is e.getCause().getTargetException() from the invoked method
  2. If it is access-related, ensure the calling code has access or use setAccessible/opens flags in the module system
  3. Fix the root exception thrown inside the invoked method
  4. Guard the reflective call with a getDeclaredMethod presence check before invoking to get a clearer error

Example fix

// before
try { ReflectionUtils.invoke(obj, "run", new Class[0]); }
catch (Exception e) { log.error("invoke failed", e); }
// after
try { ReflectionUtils.invoke(obj, "run", new Class[0]); }
catch (Exception e) {
  Throwable cause = e.getCause();
  if (cause instanceof java.lang.reflect.InvocationTargetException) {
    log.error("target method threw", cause.getCause());
  }
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-check target method accessibility
Method m = obj.getClass().getDeclaredMethod(methodName, argTypes);
m.setAccessible(true); // throws early if access is denied

Type guard

boolean isInvokable(Object o, String name, Class<?>[] types) {
  return ReflectionUtils.getDeclaredMethod(o.getClass(), name, types).isPresent();
}

Try / catch

try {
  return ReflectionUtils.invoke(obj, methodName, argTypes, args);
} catch (RuntimeException e) {
  Throwable cause = e.getCause();
  if (cause instanceof java.lang.reflect.InvocationTargetException
      && cause.getCause() != null) {
    throw new RuntimeException("target method failed", cause.getCause());
  }
  throw e;
}

Prevention

When it happens

Trigger: Any of: (a) missing method (see error 180), (b) the underlying method itself threw an exception, (c) setAccessible(true) was blocked and the method is not accessible from the caller.

Common situations: Debugging 'method invoke failed' with no detail — usually the target method threw (check the InvocationTargetException cause); Java module system or SecurityManager blocking reflective access to non-public methods; plugin exceptions surfacing wrapped in this error.

Related errors


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/507bb49222e57626. Report an issue: GitHub.