quarkusio/quarkus · error · IllegalArgumentException

Could not find a public, boolean returning method named '<me

Error message

Could not find a public, boolean returning method named '<methodName>' for bean named <beanName> with class <class> Offending expression is <expression> of @PreAuthorize on method '<methodName>' of class <class>

What it means

At build time Quarkus generates a bytecode class that invokes the bean method referenced by a @PreAuthorize SpEL expression like @myBean.isAdmin(...). determineMatchingBeanMethod scans the bean class for a method with the given name that is public, returns primitive boolean, and has exactly the expected parameter count. This IllegalArgumentException is thrown when no such method exists, so the build fails.

Source

Thrown at extensions/spring-security/deployment/src/main/java/io/quarkus/spring/security/deployment/BeanMethodInvocationGenerator.java:283

        MethodInfo matchingBeanClassMethod = null;
        for (MethodInfo candidateMethod : beanClassInfo.methods()) {
            if (candidateMethod.name().equals(methodName) &&
                    Modifier.isPublic(candidateMethod.flags()) &&
                    DotNames.PRIMITIVE_BOOLEAN.equals(candidateMethod.returnType().name()) &&
                    candidateMethod.parametersCount() == methodParametersSize) {
                if (matchingBeanClassMethod == null) {
                    matchingBeanClassMethod = candidateMethod;
                } else {
                    throw new IllegalArgumentException(
                            "Could not match a unique method name '" + methodName + "' for bean named " + beanName
                                    + " with class " + beanClassInfo.name() + " Offending expression is " +
                                    expression + " of @PreAuthorize on method '" + methodName + "' of class "
                                    + securedMethodInfo.declaringClass());
                }
            }
        }
        if (matchingBeanClassMethod == null) {
            throw new IllegalArgumentException(
                    "Could not find a public, boolean returning method named '" + methodName + "' for bean named " + beanName
                            + " with class " + beanClassInfo.name() + " Offending expression is " +
                            expression + " of @PreAuthorize on method '" + methodName + "' of class "
                            + securedMethodInfo.declaringClass());
        }
        return matchingBeanClassMethod;
    }

}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Add or fix the bean method so it is public and returns primitive boolean with exactly the same number of parameters as the arguments in the expression
  2. Correct the @PreAuthorize expression to reference the actual method name and argument list on the named bean
  3. Verify the bean name in the expression resolves to the class you think (check @Component/@Named value); a wrong bean gives the wrong class and thus no matching method

Example fix

// before
@PreAuthorize("@authz.hasRole(#name)")
String role(String name); // authz.hasRole returns String

// after
@PreAuthorize("@authz.hasRole(#name)")
String role(String name); // with: public boolean hasRole(String name) { ... }
Defensive patterns

Strategy: validation

Validate before calling

// build-time check before compiling
String expr = "@authz.isAdmin(#name)";
Class<?> beanClass = Authz.class; // resolve from bean name
Method m = Arrays.stream(beanClass.getMethods())
    .filter(mo -> mo.getName().equals("isAdmin"))
    .filter(mo -> mo.getReturnType() == boolean.class)
    .filter(mo -> mo.getParameterCount() == 1)
    .findFirst().orElse(null);
if (m == null) throw new IllegalStateException("No public boolean isAdmin(String) on " + beanClass);

Prevention

When it happens

Trigger: A @PreAuthorize("@someBean.someMethod(...)") expression names a bean method that does not exist on the bean class, is not public, does not return boolean, or has a different number of parameters than the arguments listed in the expression.

Common situations: Renaming or changing the return type of the bean method after writing the expression; forgetting that only boolean-returning methods are supported; calling a package-private/protected method; argument count mismatch (e.g. passing one argument to a two-parameter method).

Related errors


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