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

Custom ContextResolver can not be used anymore for rest client since 3.13 #46411

Closed
Postremus opened this issue Feb 21, 2025 · 2 comments · Fixed by #46413
Closed

Custom ContextResolver can not be used anymore for rest client since 3.13 #46411

Postremus opened this issue Feb 21, 2025 · 2 comments · Fixed by #46413
Milestone

Comments

@Postremus
Copy link
Member

Describe the bug

Between 3.12.3 and 3.13.0, an regression was introduced.

During my transition period from resteasy to resteasy-reactive, I needed to reliably set the used ObjectMapper for a rest client. No matter if the app run with classic or reactive. I came up with following:

{
...
WebTarget target = client.target("http://localhost:8080/hello");
target.register(new JacksonObjectMapperContextResolver());
...
}

class JacksonObjectMapperContextResolver implements ContextResolver<ObjectMapper> {

        @Override
        public ObjectMapper getContext(Class<?> type) {
            return CDI.current().select(ObjectMapper.class).get();
        }
    }

The code is obviously a few years old at this point, and I believe quarkus now automatically registers the pre configured object mapper, for classic and reactive.

When I try to use the client from above, I get the exception below in 3.13.0. With 3.12.3, worked fine.

For me, the workaround was to remove my custom context resolver.
Might still be interesting to investigate this, since this pattern is allowed according to spec afaik.

Expected behavior

Rest client should work

Actual behavior

java.lang.NullPointerException: Cannot invoke "java.lang.reflect.Method.getDeclaringClass()" because the return value of "org.jboss.resteasy.reactive.client.impl.RestClientRequestContext.getInvokedMethod()" is null
	at io.quarkus.rest.client.reactive.jackson.runtime.serialisers.JacksonUtil.getObjectMapperFromContext(JacksonUtil.java:36)
	at io.quarkus.rest.client.reactive.jackson.runtime.serialisers.ClientJacksonMessageBodyReader.getEffectiveReader(ClientJacksonMessageBodyReader.java:69)
	at io.quarkus.rest.client.reactive.jackson.runtime.serialisers.ClientJacksonMessageBodyReader.readFrom(ClientJacksonMessageBodyReader.java:51)
	at org.jboss.resteasy.reactive.client.impl.ClientReaderInterceptorContextImpl.proceed(ClientReaderInterceptorContextImpl.java:86)
	at org.jboss.resteasy.reactive.client.impl.ClientSerialisers.invokeClientReader(ClientSerialisers.java:160)
	at org.jboss.resteasy.reactive.client.impl.ClientResponseImpl.readEntity(ClientResponseImpl.java:59)
	at org.jboss.resteasy.reactive.common.jaxrs.ResponseImpl.readEntity(ResponseImpl.java:129)
	at org.acme.GreetingResource.helloInvoker(GreetingResource.java:36)
	at org.acme.GreetingResource$quarkusrestinvoker$helloInvoker_2f6939943ef199b65f5f8602b2006312f4d1106f.invoke(Unknown Source)
	at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)
	at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:141)
	at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:147)
	at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:635)
	at org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2516)
	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2495)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1521)
	at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:11)
	at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:11)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:1575)`

How to Reproduce?

man-rest-client.zip

Unzip
mvn quarkus:dev
curl localhost:8080/hello-invoker
error
change version in pom to 3.12.3
curl localhost:8080/hello-invoker
works

Output of uname -a or ver

Microsoft Windows [Version 10.0.26100.3194]

Output of java -version

openjdk 23.0.2 2025-01-21 OpenJDK Runtime Environment Temurin-23.0.2+7 (build 23.0.2+7) OpenJDK 64-Bit Server VM Temurin-23.0.2+7 (build 23.0.2+7, mixed mode, sharing)

Quarkus version or git rev

3.12.3, 3.13.0

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

Apache Maven 3.9.9 (8e8579a9e76f7d015ee5ec7bfcdc97d260186937) Maven home: C:\eclipse\tools\java\maven Java version: 23.0.2, vendor: Eclipse Adoptium, runtime: C:\eclipse\tools\java\23 Default locale: de_DE, platform encoding: UTF-8 OS name: "windows 11", version: "10.0", arch: "amd64", family: "windows"

Additional information

No response

@Postremus Postremus added the kind/bug Something isn't working label Feb 21, 2025
@quarkus-bot quarkus-bot bot added area/rest-client env/windows Impacts Windows machines labels Feb 21, 2025
Copy link

quarkus-bot bot commented Feb 21, 2025

/cc @cescoffier (rest-client), @geoand (rest-client)

@Postremus Postremus removed the env/windows Impacts Windows machines label Feb 21, 2025
geoand added a commit to geoand/quarkus that referenced this issue Feb 21, 2025
The context resolver resolution could well be happening
as part of JAX-RS Client call and not a high
level REST Client call

Fixes: quarkusio#46411
@geoand
Copy link
Contributor

geoand commented Feb 21, 2025

Good point!

#46413 fixes the issue

geoand added a commit to geoand/quarkus that referenced this issue Feb 21, 2025
The context resolver resolution could well be happening
as part of JAX-RS Client call and not a high
level REST Client call

Fixes: quarkusio#46411
@quarkus-bot quarkus-bot bot added this to the 3.21 - main milestone Feb 24, 2025
@gsmet gsmet modified the milestones: 3.21 - main, 3.19.1 Feb 24, 2025
gsmet pushed a commit to gsmet/quarkus that referenced this issue Feb 24, 2025
The context resolver resolution could well be happening
as part of JAX-RS Client call and not a high
level REST Client call

Fixes: quarkusio#46411
(cherry picked from commit ee4a8f7)
@jmartisk jmartisk modified the milestones: 3.19.1, 3.15.4 Feb 27, 2025
jmartisk pushed a commit to jmartisk/quarkus that referenced this issue Feb 27, 2025
The context resolver resolution could well be happening
as part of JAX-RS Client call and not a high
level REST Client call

Fixes: quarkusio#46411
(cherry picked from commit ee4a8f7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants