{"record":{"id":"015df3ac07246fb5","repo":"quarkusio/quarkus","slug":"dynamic-constructor-parameter-constraint-violati","errorCode":null,"errorMessage":"(dynamic: constructor parameter constraint violations summary)","messagePattern":"\\(dynamic: constructor parameter constraint violations summary\\)","errorType":"validation","errorClass":"ConstraintViolationException","httpStatus":null,"severity":"error","filePath":"extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/interceptor/AbstractMethodValidationInterceptor.java","lineNumber":102,"sourceCode":"\n    /**\n     * Validates the Bean Validation constraints specified at the parameters and/or\n     * return value of the intercepted constructor.\n     *\n     * @param ctx The context of the intercepted constructor invocation.\n     *\n     * @throws Exception Any exception caused by the intercepted constructor\n     *         invocation. A {@link ConstraintViolationException} in case\n     *         at least one constraint violation occurred either during\n     *         parameter or return value validation.\n     */\n    protected void validateConstructorInvocation(InvocationContext ctx) throws Exception {\n        ExecutableValidator executableValidator = validatorInstance.get().forExecutables();\n        Set<? extends ConstraintViolation<?>> violations = executableValidator\n                .validateConstructorParameters(ctx.getConstructor(), ctx.getParameters());\n\n        if (!violations.isEmpty()) {\n            throw new ConstraintViolationException(getMessage(ctx.getConstructor(), ctx.getParameters(), violations),\n                    violations);\n        }\n\n        ctx.proceed();\n        Object createdObject = ctx.getTarget();\n\n        violations = executableValidator.validateConstructorReturnValue(ctx.getConstructor(),\n                createdObject);\n\n        if (!violations.isEmpty()) {\n            throw new ConstraintViolationException(getMessage(ctx.getConstructor(), ctx.getParameters(), violations),\n                    violations);\n        }\n    }\n\n    private String getMessage(Member member, Object[] args, Set<? extends ConstraintViolation<?>> violations) {\n\n        StringBuilder message = new StringBuilder();","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/interceptor/AbstractMethodValidationInterceptor.java#L84-L120","documentation":"Thrown by the method-validation interceptor when constructor parameters violate Bean Validation constraints. ExecutableValidator.validateConstructorParameters runs before the constructor body executes; any violation results in a ConstraintViolationException carrying a summary listing the constructor, argument values, and each violation, so the object is never created.","triggerScenarios":"Instantiating a bean whose constructor parameters carry constraints (e.g. @NotNull String config, @Min(1) int threads) via CDI with method validation enabled, passing invalid arguments; thrown at AbstractMethodValidationInterceptor.java:101-104 before ctx.proceed().","commonSituations":"Programmatic CDI lookup or Instance.get() with invalid constructor arguments; factory classes creating validated beans with config values that fail @Min/@Max/@Pattern; misconfigured application properties injected through constrained constructors.","solutions":["Read the violations from getConstraintViolations() to identify the offending parameter index and constraint.","Correct the arguments passed to the constructor, or validate config earlier (e.g. via @ConfigMapping with validation).","Adjust or remove the constructor-parameter constraints if they are too strict for legitimate inputs.","Pre-validate inputs before requesting the bean instance from CDI."],"exampleFix":"// before\npublic Worker(@Min(1) int threads) { ... }\nContainer.instance().select(Worker.class) with threads=0 // throws\n\n// after\nContainer.instance().select(Worker.class) with threads=1; // passes @Min(1)","handlingStrategy":"validation","validationCode":"Set<? extends ConstraintViolation<?>> v = validator.forExecutables().validateConstructorParameters(ctor, args);\nif (!v.isEmpty()) { /* do not instantiate */ }","typeGuard":"boolean canConstruct = args[0] != null && threads >= 1; // mirror declared constraints","tryCatchPattern":"try { Worker w = instance.get(); } catch (ConstraintViolationException e) { // constructor never ran; inspect violations }","preventionTips":["Mirror constructor constraints in factory/creator code before instantiating","Use @ConfigMapping validation for configuration instead of constructor constraints","Test bean creation with boundary argument values","Catch ConstraintViolationException at bean-acquisition boundaries and report config errors clearly"],"tags":["bean-validation","constraint-violation","constructor","cdi"],"backgroundTag":"constraint-violation-exception","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"}