Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid config value prevents app to startup with invalid stacktrace instead of validation error message #31434

Closed
luca-bassoricci opened this issue Feb 27, 2023 · 9 comments · Fixed by #31518
Labels
area/smallrye env/windows Impacts Windows machines kind/bug Something isn't working
Milestone

Comments

@luca-bassoricci
Copy link
Contributor

luca-bassoricci commented Feb 27, 2023

Describe the bug

https://stackoverflow.com/questions/75535327/hibernate-validator-for-smallrye-quarkus-configmapping-throwing-exception-and-n

I faced the same problem yesterday; the problem is in io.quarkus.hibernate.validator.runtime.locale.ResteasyReactiveLocaleResolver.resolve(line 18) because a @RequestContext object is requested and request scope is not active.

Expected behavior

Application should not start but with the right validation error message

Actual behavior

Caused by: javax.validation.ValidationException: HV000149: An exception occurred during message interpolation
	at org.hibernate.validator.internal.engine.validationcontext.AbstractValidationContext.interpolate(AbstractValidationContext.java:331)
	at org.hibernate.validator.internal.engine.validationcontext.AbstractValidationContext.addConstraintFailure(AbstractValidationContext.java:231)
	at org.hibernate.validator.internal.engine.validationcontext.ReturnValueExecutableValidationContext.addConstraintFailure(ReturnValueExecutableValidationContext.java:31)
	at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:79)
	at org.hibernate.validator.internal.metadata.core.MetaConstraint.doValidateConstraint(MetaConstraint.java:130)
	at org.hibernate.validator.internal.metadata.core.MetaConstraint.validateConstraint(MetaConstraint.java:123)
	at org.hibernate.validator.internal.engine.ValidatorImpl.validateMetaConstraint(ValidatorImpl.java:555)
	at org.hibernate.validator.internal.engine.ValidatorImpl.validateMetaConstraints(ValidatorImpl.java:537)
	at org.hibernate.validator.internal.engine.ValidatorImpl.validateReturnValueForSingleGroup(ValidatorImpl.java:1141)
	at org.hibernate.validator.internal.engine.ValidatorImpl.validateReturnValueForGroup(ValidatorImpl.java:1111)
	at org.hibernate.validator.internal.engine.ValidatorImpl.validateReturnValueInContext(ValidatorImpl.java:1033)
	at org.hibernate.validator.internal.engine.ValidatorImpl.validateReturnValue(ValidatorImpl.java:309)
	at org.hibernate.validator.internal.engine.ValidatorImpl.validateReturnValue(ValidatorImpl.java:259)
	at io.smallrye.config.validator.BeanValidationConfigValidator.validatePropertyValue(BeanValidationConfigValidator.java:195)
	at io.smallrye.config.validator.BeanValidationConfigValidator.validateProperty(BeanValidationConfigValidator.java:77)
	at io.smallrye.config.validator.BeanValidationConfigValidator.validateMappingInterface(BeanValidationConfigValidator.java:57)
	at io.smallrye.config.validator.BeanValidationConfigValidator.validateMapping(BeanValidationConfigValidator.java:39)
	at io.smallrye.config.ConfigMappings.getConfigMapping(ConfigMappings.java:124)
	at io.smallrye.config.SmallRyeConfig.getConfigMapping(SmallRyeConfig.java:411)
	at io.quarkus.arc.runtime.ConfigMappingCreator.create(ConfigMappingCreator.java:31)
	at org.acme.Config_b24e5fd41538df60276cea46d90faaf3bfa88dc9_Synthetic_Bean.create(Unknown Source)
	at org.acme.Config_b24e5fd41538df60276cea46d90faaf3bfa88dc9_Synthetic_Bean.get(Unknown Source)
	at org.acme.Config_b24e5fd41538df60276cea46d90faaf3bfa88dc9_Synthetic_Bean.get(Unknown Source)
	at io.quarkus.arc.impl.CurrentInjectionPointProvider.get(CurrentInjectionPointProvider.java:62)
	... 80 more
Caused by: javax.enterprise.context.ContextNotActiveException: RequestScoped context was not active when trying to obtain a bean instance for a client proxy of CLASS bean [class=io.quarkus.vertx.http.runtime.CurrentVertxRequest, id=9260aa608251c44230eeb9b234f605844a7622bf]
	- you can activate the request context for a specific method using the @ActivateRequestContext interceptor binding
	at io.quarkus.arc.impl.ClientProxies.getDelegate(ClientProxies.java:55)
	at io.quarkus.vertx.http.runtime.CurrentVertxRequest_ClientProxy.arc$delegate(Unknown Source)
	at io.quarkus.vertx.http.runtime.CurrentVertxRequest_ClientProxy.getCurrent(Unknown Source)
	at io.quarkus.hibernate.validator.runtime.locale.ResteasyReactiveLocaleResolver.getHeaders(ResteasyReactiveLocaleResolver.java:26)
	at io.quarkus.hibernate.validator.runtime.locale.AbstractLocaleResolver.getAcceptableLanguages(AbstractLocaleResolver.java:31)
	at io.quarkus.hibernate.validator.runtime.locale.AbstractLocaleResolver.resolve(AbstractLocaleResolver.java:17)
	at io.quarkus.hibernate.validator.runtime.locale.ResteasyReactiveLocaleResolver.resolve(ResteasyReactiveLocaleResolver.java:18)
	at io.quarkus.hibernate.validator.runtime.locale.LocaleResolversWrapper.resolve(LocaleResolversWrapper.java:27)
	at org.hibernate.validator.messageinterpolation.AbstractMessageInterpolator.interpolate(AbstractMessageInterpolator.java:343)
	at org.hibernate.validator.internal.engine.validationcontext.AbstractValidationContext.interpolate(AbstractValidationContext.java:322)
	... 103 more

How to Reproduce?

https://github.com/luca-bassoricci/code-with-quarkus

build with latest version but also fails with older versions

Output of uname -a or ver

Windows 11

Output of java -version

No response

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.16.3.Final

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

Removing quarkus-resteasy-reactive will solve the problem.
I had the same problem in backend code which interacts with some @RestClients during validation of PanacheEntity just before persisting, but I am unable to write a reproducer.

@luca-bassoricci luca-bassoricci added the kind/bug Something isn't working label Feb 27, 2023
@quarkus-bot
Copy link

quarkus-bot bot commented Feb 27, 2023

/cc @brunobat (opentelemetry,tracing), @radcortez (opentelemetry,tracing)

@luca-bassoricci
Copy link
Contributor Author

#31518 (comment)

I found when the problem is present in our backend code: during execution of any Quartz Job the request-scope is not automatically activated; this behaviour differs from simple-scheduler extension where request-scope is activated by scheduler' method invoker (see https://github.com/quarkusio/quarkus/blob/9285df280499ce3202a0f3f94b5b6549dd659ff0/extensions/scheduler/common/src/main/java/io/quarkus/scheduler/common/runtime/DefaultInvoker.java).

Should Quartz scheduler activate request-scope as simple scheduler or must be a user choice (eg. using @ActivateRequestScope on org.quartz.job.Job#execute(JobExecutionContext))?

/cc @gsmet

@geoand
Copy link
Contributor

geoand commented Mar 6, 2023

Should Quartz scheduler activate request-scope as simple scheduler or must be a user choice (eg. using @ActivateRequestScope on org.quartz.job.Job#execute(JobExecutionContext))?

I am pretty we have discussed this before and decided against it because scheduled jobs can be very long running.
cc @mkouba who might remember

@luca-bassoricci
Copy link
Contributor Author

Reading around Quarkus documentation I understood that the request-scope is a wide concept in Quarkus and it's not strictly tied to HTTP request; why how the request duration can be a discriminator for request-scope activation?

I'm asking that because I was temped to activate request scope in our quartz' jobs to be able to use @RequestScoped beans or the right way is to declare them @Dependent?

@geoand
Copy link
Contributor

geoand commented Mar 6, 2023

Reading around Quarkus documentation I understood that the request-scope is a wide concept in Quarkus and it's not strictly tied to HTTP request; why how the request duration can be a discriminator for request-scope activation?

It ties up hardware resources

@mkouba
Copy link
Contributor

mkouba commented Mar 9, 2023

I think that we do activate the request context even for a Quartz scheduled job, unless it's a kotlin continuation; i.e. the DefaultInvoker is used for both the simple and the quartz impl and there's even a test: https://github.com/quarkusio/quarkus/blob/main/extensions/quartz/deployment/src/test/java/io/quarkus/quartz/test/RequestScheduledMethodTest.java

@luca-bassoricci
Copy link
Contributor Author

@mkouba
Copy link
Contributor

mkouba commented Mar 9, 2023

@mkouba

I added a small reproducer (https://github.com/luca-bassoricci/contextnotactive_issue) similar at https://github.com/quarkusio/quarkus/blob/main/extensions/quartz/deployment/src/test/java/io/quarkus/quartz/test/InjectJobTest.java and @Entity validation is still failing with ContextNotActivateException

Wait a minute - you don't use the Quakus API in this reproducer, i.e. no @Scheduled method (or the programmatic approach introduced in 3.x). In that case, it's completely up to you, because we don't control the "registration" of the org.acme.quartz.QuartzInvoiceJob.

@luca-bassoricci
Copy link
Contributor Author

So I must annotate @ActivateRequestContext QuartzInvoiceJob#execute() to have the request scope active during job execution, right?

@gsmet gsmet modified the milestones: 3.0.0.Alpha5, 2.16.9.Final Jul 26, 2023
gsmet pushed a commit to gsmet/quarkus that referenced this issue Jul 28, 2023
Check for an active RequestContext before accessing
ResteasyReactiveLocaleResolver#currentVertxRequest to prevent
ContextNotActiveException

(cherry picked from commit da65125)
@gsmet gsmet modified the milestones: 2.16.9.Final, 2.13.9.Final Nov 15, 2023
gsmet pushed a commit to gsmet/quarkus that referenced this issue Nov 15, 2023
Check for an active RequestContext before accessing
ResteasyReactiveLocaleResolver#currentVertxRequest to prevent
ContextNotActiveException

(cherry picked from commit da65125)
gsmet pushed a commit to gsmet/quarkus that referenced this issue Nov 15, 2023
Check for an active RequestContext before accessing
ResteasyReactiveLocaleResolver#currentVertxRequest to prevent
ContextNotActiveException

(cherry picked from commit da65125)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/smallrye env/windows Impacts Windows machines kind/bug Something isn't working
Projects
None yet
5 participants