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

A NoSuchMethodException is raised when a REST resource is called with a single JsonObject argument in native build #45084

Closed
nikolassv opened this issue Dec 12, 2024 · 5 comments · Fixed by #45097
Labels
Milestone

Comments

@nikolassv
Copy link
Contributor

Describe the bug

I have a simple resource that exposes a single POST endpoint which consumes JSON, produces a plaintext and has a single argument of type JsonObject. When I build this application natively and call the endpoint with a JSON string it raises a NoSuchMethodException.

A JVM build works just fine: The endpoint returns the message string.

Expected behavior

The endpoint should return the message string from the JSON request object.

Actual behavior

It raises a NoSuchMethodException:

2024-12-12 10:30:01,625 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (executor-thread-1) HTTP Request to /hello failed, error id: d1eeb235-2f75-472c-9e5c-a56e242e9298-1: java.lang.RuntimeException: java.lang.NoSuchMethodException: org.acme.ExampleResource.post(jakarta.json.JsonObject)
        at org.jboss.resteasy.reactive.server.spi.ResteasyReactiveResourceInfo.getMethod(ResteasyReactiveResourceInfo.java:84)
        at org.jboss.resteasy.reactive.server.spi.ResteasyReactiveResourceInfo.getParameterAnnotations(ResteasyReactiveResourceInfo.java:125)
        at org.jboss.resteasy.reactive.server.handlers.RequestDeserializeHandler.getAnnotations(RequestDeserializeHandler.java:133)
        at org.jboss.resteasy.reactive.server.handlers.RequestDeserializeHandler.isReadable(RequestDeserializeHandler.java:118)
        at org.jboss.resteasy.reactive.server.handlers.RequestDeserializeHandler.handle(RequestDeserializeHandler.java:78)
        at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:135)
        at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:147)
        at io.quarkus.vertx.core.runtime.VertxCoreRecorder$15.runWith(VertxCoreRecorder.java:637)
        at org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2675)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2654)
        at org.jboss.threads.EnhancedQueueExecutor.runThreadBody(EnhancedQueueExecutor.java:1627)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1594)
        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@21/java.lang.Thread.runWith(Thread.java:1596)
        at java.base@21/java.lang.Thread.run(Thread.java:1583)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:833)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:211)
Caused by: java.lang.NoSuchMethodException: org.acme.ExampleResource.post(jakarta.json.JsonObject)
        at java.base@21/java.lang.Class.checkMethod(DynamicHub.java:1065)
        at java.base@21/java.lang.Class.getMethod(DynamicHub.java:1050)
        at org.jboss.resteasy.reactive.server.spi.ResteasyReactiveResourceInfo.getMethod(ResteasyReactiveResourceInfo.java:79)
        ... 18 more

How to Reproduce?

  1. Create a simple endpoint like this:
@Path("/hello")
public class ExampleResource {

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.TEXT_PLAIN)
    public String post(JsonObject request) {
        return request.getString("message");
    }
}
  1. Create a native build of the application and run it
  2. Send a http request like this:
POST http://localhost:8080/hello
Content-Type: application/json

{
  "message": "In a bottle"
}

For a reproducer see: https://github.com/nikolassv/quarkus-reproducer-rest-nosuchmethodexception

Output of uname -a or ver

Linux 5.15.167.4-microsoft-standard-WSL2 #1 SMP Tue Nov 5 00:21:55 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version "21" 2023-09-19 OpenJDK Runtime Environment GraalVM CE 21+35.1 (build 21+35-jvmci-23.1-b15) OpenJDK 64-Bit Server VM GraalVM CE 21+35.1 (build 21+35-jvmci-23.1-b15, mixed mode, sharing)

Mandrel or GraalVM version (if different from Java)

No response

Quarkus version or git rev

3.17.4

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

Apache Maven 3.9.9 (8e8579a9e76f7d015ee5ec7bfcdc97d260186937)

Additional information

No response

@nikolassv nikolassv added area/native-image kind/bug Something isn't working labels Dec 12, 2024
Copy link

quarkus-bot bot commented Dec 12, 2024

/cc @Karm (mandrel), @galderz (mandrel), @zakkak (mandrel,native-image)

@nikolassv nikolassv changed the title A NoSuchMethodException is raised when a REST resource is called with an single JsonObject argument in native build A NoSuchMethodException is raised when a REST resource is called with a single JsonObject argument in native build Dec 12, 2024
@manofthepeace
Copy link
Contributor

I would suggest you use <artifactId>quarkus-rest-jackson</artifact> and use Jackson's JsonNode, ObjectNode, Arraynode type. Then it would just work OOTB.

Tested with
public String post(ObjectNode request) {
return request.get("message").asText();
}
❯ curl -d '{"message":"In a Bottle"}' -H "Content-Type: application/json" -X POST http://localhost:8080/hello
In a Bottle%

@gsmet
Copy link
Member

gsmet commented Dec 12, 2024

Even if there is a workaround, that's probably something we should fix. It looks related to a few issues @geoand has been fixing recently.

@geoand
Copy link
Contributor

geoand commented Dec 12, 2024

Absolutely!

@geoand
Copy link
Contributor

geoand commented Dec 12, 2024

#45097 fixes the problem

@geoand geoand closed this as completed in 0879ce4 Dec 13, 2024
geoand added a commit that referenced this issue Dec 13, 2024
Ensure that jakarta json types can be deserialized in native mode
@quarkus-bot quarkus-bot bot added this to the 3.18 - main milestone Dec 13, 2024
ankushnitcode pushed a commit to ankushnitcode/quarkus that referenced this issue Dec 13, 2024
@gsmet gsmet modified the milestones: 3.18 - main, 3.17.5 Dec 17, 2024
gsmet pushed a commit to gsmet/quarkus that referenced this issue Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants