quarkus: Hibernate validation fails on a constructor parameter validation
Describe the bug
I am getting a Hibernate exception like the one below when trying to add validation to the bean constructor method like this:
@ApplicationScoped
public class GrpcMetadataResolver {
@Inject
public GrpcMetadataResolver(GrpcMetadataConfig config, @SourceApi @Pattern(regexp = "rest|graphql") String sourceApi) {
...
}
}
Removing the @Pattern(regexp = "rest|graphql")
makes the injection to work fine.
The stack trace from the cause:
Caused by: java.lang.IllegalArgumentException: HV000181: Wrong number of parameters. Method or constructor class io.stargate.sgv2.api.common.grpc.GrpcMetadataResolver#GrpcMetadataResolver(GrpcMetadataConfig, String) expects 2 parameters, but got 0.
at org.hibernate.validator.internal.engine.ValidatorImpl.validateParametersInContext(ValidatorImpl.java:842)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateParameters(ValidatorImpl.java:283)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstructorParameters(ValidatorImpl.java:243)
at io.quarkus.hibernate.validator.runtime.interceptor.AbstractMethodValidationInterceptor.validateConstructorInvocation(AbstractMethodValidationInterceptor.java:97)
at io.quarkus.hibernate.validator.runtime.interceptor.MethodValidationInterceptor.validateConstructorInvocation(MethodValidationInterceptor.java:23)
at io.quarkus.hibernate.validator.runtime.interceptor.MethodValidationInterceptor_Bean.intercept(Unknown Source)
at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:42)
at io.quarkus.arc.impl.LifecycleCallbackInvocationContext.invokeNext(LifecycleCallbackInvocationContext.java:53)
at io.quarkus.arc.impl.LifecycleCallbackInvocationContext.proceed(LifecycleCallbackInvocationContext.java:28)
... 202 more
Not sure if there are some config props to handle this behavior? I am sure why would the hibernate go for the no-args constructor here?
Expected behavior
Injection and validation works.
Actual behavior
No response
How to Reproduce?
No response
Output of uname -a
or ver
No response
Output of java -version
No response
GraalVM version (if different from Java)
No response
Quarkus version or git rev
2.13.2.Final
Build tool (ie. output of mvnw --version
or gradlew --version
)
Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537) Maven home: /home/ise/.m2/wrapper/dists/apache-maven-3.8.4-bin/52ccbt68d252mdldqsfsn03jlf/apache-maven-3.8.4 Java version: 17.0.4, vendor: Private Build, runtime: /usr/lib/jvm/java-17-openjdk-amd64 Default locale: en_US, platform encoding: UTF-8 OS name: “linux”, version: “5.15.0-52-generic”, arch: “amd64”, family: “unix”
Additional information
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 26 (25 by maintainers)
I’ve sent https://github.com/quarkusio/quarkus/pull/29094 as an attempt to fix this.
Wow this was fixed fast 🚀