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

java.lang.NoSuchMethodException on native build when using MessageBodyReader with extended class #27167

Closed
guliguligagaga opened this issue Aug 6, 2022 · 1 comment · Fixed by #27182
Labels
area/rest kind/bug Something isn't working
Milestone

Comments

@guliguligagaga
Copy link

guliguligagaga commented Aug 6, 2022

Describe the bug

Hey guys,

When I tried to use MessageBodyReader to put header values directly into request, it works with jvm but not with native.

@Provider
public class AccountInfoHandler implements MessageBodyReader<AccountInfo> {

    @Inject
    ObjectMapper objectMapper;

    public boolean isReadable(Class<?> type, Type genericType,
                              Annotation[] annotations, MediaType mediaType) {
        return AccountInfo.class.isAssignableFrom(type);
    }

    public AccountInfo readFrom(Class<AccountInfo> type, Type genericType,
                                Annotation[] annotations, MediaType mediaType,
                                MultivaluedMap<String, String> httpHeaders,
                                InputStream entityStream)
            throws IOException, WebApplicationException {
        AccountInfo accountInfo = objectMapper.readValue(entityStream, type);
        accountInfo.accountId = httpHeaders.getFirst("x-id");
        return accountInfo;
    }

}

@RegisterForReflection
public class Request extends AccountInfo {
    public String field;
}
@RegisterForReflection
public class AccountInfo {
    public String accountId;
}

and controllers

@Path("/test")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class Controller {

    @POST
    @Path("/post")
    public Uni<Request> post(Request request) {
        return Uni.createFrom().item(request);
    }

}

Expected behavior

Same as the JVM build:

curl --header "x-id: 123" -H "Content-Type: application/json" -d '{ }' -X POST http://127.0.0.1:8080/test/post   

{"accountId":"123","field":null}  

Actual behavior

curl --header "x-id: 123" -H "Content-Type: application/json" -d '{ }' -X POST http://127.0.0.1:8080/test/post
{"details":"Error id a2d0e734-6cbb-4aad-bf08-69985a5ce304-1","stack":""}%
2022-08-06 18:53:51,674 ERROR [org.jbo.res.rea.com.cor.AbstractResteasyReactiveContext] (vert.x-eventloop-thread-3) Request failed: java.lang.RuntimeException: java.lang.NoSuchMethodException: classes.Controller.post(classes.model.Request)
        at org.jboss.resteasy.reactive.server.spi.ResteasyReactiveResourceInfo.getMethod(ResteasyReactiveResourceInfo.java:70)
        at org.jboss.resteasy.reactive.server.spi.ResteasyReactiveResourceInfo.getParameterAnnotations(ResteasyReactiveResourceInfo.java:111)
        at org.jboss.resteasy.reactive.server.handlers.RequestDeserializeHandler.getAnnotations(RequestDeserializeHandler.java:115)
        at org.jboss.resteasy.reactive.server.handlers.RequestDeserializeHandler.isReadable(RequestDeserializeHandler.java:100)
        at org.jboss.resteasy.reactive.server.handlers.RequestDeserializeHandler.handle(RequestDeserializeHandler.java:61)
        at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:102)
        at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:140)
        at org.jboss.resteasy.reactive.server.vertx.VertxResteasyReactiveRequestContext$1$1.handle(VertxResteasyReactiveRequestContext.java:74)
        at org.jboss.resteasy.reactive.server.vertx.VertxResteasyReactiveRequestContext$1$1.handle(VertxResteasyReactiveRequestContext.java:71)
        at io.vertx.core.impl.ContextInternal.dispatch(ContextInternal.java:264)
        at io.vertx.core.impl.ContextInternal.dispatch(ContextInternal.java:246)
        at io.vertx.core.impl.EventLoopContext.lambda$runOnContext$0(EventLoopContext.java:43)
        at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174)
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:167)
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.lang.Thread.run(Thread.java:833)
        at com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:705)
        at com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:202)
Caused by: java.lang.NoSuchMethodException: classes.Controller.post(classes.model.Request)
        at java.lang.Class.getMethod(DynamicHub.java:2227)
        at org.jboss.resteasy.reactive.server.spi.ResteasyReactiveResourceInfo.getMethod(ResteasyReactiveResourceInfo.java:65)
        ... 21 more

How to Reproduce?

https://github.com/guliguligagaga/quarkus-resteasy-reactive

Output of uname -a or ver

Darwin MacBook-Pro.local 21.6.0 Darwin Kernel Version 21.6.0: Sat Jun 18 17:05:47 PDT 2022; root:xnu-8020.140.41~1/RELEASE_ARM64_T8101 arm64

Output of java -version

openjdk version "17.0.4" 2022-07-19 OpenJDK Runtime Environment GraalVM CE 22.2.0 (build 17.0.4+8-jvmci-22.2-b06) OpenJDK 64-Bit Server VM GraalVM CE 22.2.0 (build 17.0.4+8-jvmci-22.2-b06, mixed mode, sharing)

GraalVM version (if different from Java)

GraalVM CE 22.2.0 (build 17.0.4+8-jvmci-22.2-b06)

Quarkus version or git rev

2.11.2.Final

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

Maven 3.8.1

Additional information

No response

@geoand
Copy link
Contributor

geoand commented Aug 8, 2022

Thanks, #27182 takes care of it

geoand added a commit that referenced this issue Aug 8, 2022
Ensure that custom MessageBodyReader classes work properly in native mode
@quarkus-bot quarkus-bot bot added this to the 2.12 - main milestone Aug 8, 2022
@gsmet gsmet modified the milestones: 2.12.0.CR1, 2.11.3.Final Aug 23, 2022
gsmet pushed a commit to gsmet/quarkus that referenced this issue Aug 23, 2022
miador pushed a commit to miador/quarkus that referenced this issue Sep 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/rest kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants