From 536d8ca78e74aed0f85e98d70af3931ef43e6287 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Wed, 26 Jan 2022 09:37:14 +0200 Subject: [PATCH] Guard against ContextNotActiveException in ResteasyReactiveContextLocaleResolver Fixes: #23195 --- .../ResteasyReactiveContextLocaleResolver.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/jaxrs/ResteasyReactiveContextLocaleResolver.java b/extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/jaxrs/ResteasyReactiveContextLocaleResolver.java index 9f4023f718699..aaef5de8f3b91 100644 --- a/extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/jaxrs/ResteasyReactiveContextLocaleResolver.java +++ b/extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/jaxrs/ResteasyReactiveContextLocaleResolver.java @@ -1,8 +1,10 @@ package io.quarkus.hibernate.validator.runtime.jaxrs; +import javax.enterprise.context.RequestScoped; import javax.inject.Singleton; import javax.ws.rs.core.HttpHeaders; +import io.quarkus.arc.Arc; import io.quarkus.arc.DefaultBean; @Singleton @@ -18,11 +20,14 @@ public ResteasyReactiveContextLocaleResolver(HttpHeaders headers) { @Override protected HttpHeaders getHeaders() { - try { - headers.getLength(); // this forces the creation of the actual object which will fail if there is no request in flight - return headers; - } catch (IllegalStateException e) { - return null; + if (Arc.container().getActiveContext(RequestScoped.class) != null) { // only try to obtain headers if there is a request scope + try { + headers.getLength(); // this forces the creation of the actual object which will fail if there is no request in flight + return headers; + } catch (IllegalStateException ignored) { + + } } + return null; } }