quarkusio/quarkus · error · java.lang.RuntimeException

Cannot invoke method: ${className}#${name} on ${instance}

Error message

Cannot invoke method: ${className}#${name} on ${instance}

What it means

When Reflections.invokeMethod() calls a method reflectively and the method itself throws a checked exception (wrapped in InvocationTargetException, and not a RuntimeException), ArC rethrows it as this RuntimeException naming the class, method, and target instance. The original failure is attached as the cause.

Source

Thrown at independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/Reflections.java:188

            field.set(instance, value);
        } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
            throw new RuntimeException("Cannot set field value: " + clazz.getName() + "#" + name, e);
        }
    }

    public static Object invokeMethod(Class<?> clazz, String name, Class<?>[] paramTypes, Object instance, Object[] args) {
        try {
            Method method = clazz.getDeclaredMethod(name, paramTypes);
            if (!method.canAccess(instance)) {
                method.setAccessible(true);
            }
            return method.invoke(instance, args);
        } catch (InvocationTargetException e) {
            Throwable t = e.getTargetException();
            if (t instanceof RuntimeException) {
                throw (RuntimeException) t;
            }
            throw new RuntimeException("Cannot invoke method: " + clazz.getName() + "#" + name + " on " + instance, e);
        } catch (NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
            throw new RuntimeException("Cannot invoke method: " + clazz.getName() + "#" + name + " on " + instance, e);
        }
    }

    @SuppressWarnings("unchecked")
    static <T> T cast(Object obj) {
        return (T) obj;
    }

    @SuppressWarnings("unchecked")
    public static <T> Class<T> getRawType(Type type) {
        if (type instanceof Class<?>) {
            return (Class<T>) type;
        }
        if (isParameterizedType(type)) {
            final ParameterizedType parameterizedType = asParameterizedType(type);
            if (parameterizedType.getRawType() instanceof Class<?>) {

View on GitHub (pinned to e1c734241f)

Solutions

  1. Inspect the cause (InvocationTargetException#getTargetException) for the real failure
  2. Fix the underlying checked exception thrown by the target method
  3. Catch and handle the checked exception inside the invoked method, or change it to throw a RuntimeException
  4. Validate inputs/instance state before the reflective call so the method succeeds

Example fix

// before
public void doWork() throws IOException { Files.readAllBytes(path); }
// after
public void doWork() { try { Files.readAllBytes(path); } catch (IOException e) { throw new UncheckedIOException(e); } }
Defensive patterns

Strategy: try-catch

Try / catch

try { return Reflections.invokeMethod(clazz, name, types, instance, args); }
catch (RuntimeException e) {
    Throwable cause = e.getCause();
    if (cause != null) log.error("Target threw " + cause, cause);
    throw e;
}

Prevention

When it happens

Trigger: Invoking a method via Reflections.invokeMethod() whose target throws a checked/non-Runtime Throwable; the InvocationTargetException path re-wraps it since only RuntimeExceptions are unwrapped and rethrown directly.

Common situations: Bean callbacks or interceptor-invoked methods throwing checked exceptions during tests; reflective invocation of a method doing I/O that fails; debugging why a wrapped checked exception surfaced from container code.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/2b12bbf0d1dfb3ff. Report an issue: GitHub.