{"record":{"id":"700ea3a42e72c087","repo":"quarkusio/quarkus","slug":"could-not-find-a-public-boolean-returning-method","errorCode":null,"errorMessage":"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>","messagePattern":"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>","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/spring-security/deployment/src/main/java/io/quarkus/spring/security/deployment/BeanMethodInvocationGenerator.java","lineNumber":283,"sourceCode":"        MethodInfo matchingBeanClassMethod = null;\n        for (MethodInfo candidateMethod : beanClassInfo.methods()) {\n            if (candidateMethod.name().equals(methodName) &&\n                    Modifier.isPublic(candidateMethod.flags()) &&\n                    DotNames.PRIMITIVE_BOOLEAN.equals(candidateMethod.returnType().name()) &&\n                    candidateMethod.parametersCount() == methodParametersSize) {\n                if (matchingBeanClassMethod == null) {\n                    matchingBeanClassMethod = candidateMethod;\n                } else {\n                    throw new IllegalArgumentException(\n                            \"Could not match a unique method name '\" + methodName + \"' for bean named \" + beanName\n                                    + \" with class \" + beanClassInfo.name() + \" Offending expression is \" +\n                                    expression + \" of @PreAuthorize on method '\" + methodName + \"' of class \"\n                                    + securedMethodInfo.declaringClass());\n                }\n            }\n        }\n        if (matchingBeanClassMethod == null) {\n            throw new IllegalArgumentException(\n                    \"Could not find a public, boolean returning method named '\" + methodName + \"' for bean named \" + beanName\n                            + \" with class \" + beanClassInfo.name() + \" Offending expression is \" +\n                            expression + \" of @PreAuthorize on method '\" + methodName + \"' of class \"\n                            + securedMethodInfo.declaringClass());\n        }\n        return matchingBeanClassMethod;\n    }\n\n}\n","sourceCodeStart":265,"sourceCodeEnd":293,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/spring-security/deployment/src/main/java/io/quarkus/spring/security/deployment/BeanMethodInvocationGenerator.java#L265-L293","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","solutions":["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","Correct the @PreAuthorize expression to reference the actual method name and argument list on the named bean","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"],"exampleFix":"// before\n@PreAuthorize(\"@authz.hasRole(#name)\")\nString role(String name); // authz.hasRole returns String\n\n// after\n@PreAuthorize(\"@authz.hasRole(#name)\")\nString role(String name); // with: public boolean hasRole(String name) { ... }","handlingStrategy":"validation","validationCode":"// build-time check before compiling\nString expr = \"@authz.isAdmin(#name)\";\nClass<?> beanClass = Authz.class; // resolve from bean name\nMethod m = Arrays.stream(beanClass.getMethods())\n    .filter(mo -> mo.getName().equals(\"isAdmin\"))\n    .filter(mo -> mo.getReturnType() == boolean.class)\n    .filter(mo -> mo.getParameterCount() == 1)\n    .findFirst().orElse(null);\nif (m == null) throw new IllegalStateException(\"No public boolean isAdmin(String) on \" + beanClass);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep every bean method referenced in @PreAuthorize public and boolean-returning","Match the argument count in the expression to the method's parameter count exactly","Rebuild after renaming/refactoring bean methods so build-time validation catches mismatches"],"tags":["spring-security","build-time","preauthorize","bean-method"],"backgroundTag":"preauthorize-bean-method-not-found","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}