snowdrop-zen / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
1 stars 0 forks source link

Non static inner class as JAX-RS Resource produces obscure error #403

Closed snowdrop-bot closed 3 years ago

snowdrop-bot commented 3 years ago

Describe the bug

running this script with jbang -Dquarkus.dev main.java and it fails but update to use resteasy and it works.

Error shown with resteasy-reactive:

java.lang.NoSuchMethodException: main$PersonResource.<init>()
    at java.base/java.lang.Class.getConstructor0(Class.java:3350)
    at java.base/java.lang.Class.getDeclaredConstructor(Class.java:2554)
    at io.quarkus.arc.runtime.BeanContainerImpl$DefaultInstanceFactory.create(BeanContainerImpl.java:68)
    at io.quarkus.resteasy.reactive.common.runtime.ArcBeanFactory.createInstance(ArcBeanFactory.java:25)
    at org.jboss.resteasy.reactive.server.handlers.InstanceHandler.handle(InstanceHandler.java:26)
    at org.jboss.resteasy.reactive.server.handlers.InstanceHandler.handle(InstanceHandler.java:7)
    at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:141)
    at io.quarkus.vertx.core.runtime.VertxCoreRecorder$13.runWith(VertxCoreRecorder.java:543)
    at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
    at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
    at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.base/java.lang.Thread.run(Thread.java:834)
Resulted in: java.lang.RuntimeException: java.lang.NoSuchMethodException: main$PersonResource.<init>()
    at io.quarkus.arc.runtime.BeanContainerImpl$DefaultInstanceFactory.create(BeanContainerImpl.java:76)
    ... 11 more

Expected behavior

that resteasy-reactive does not change panache/jaxrs behavior.

Actual behavior

No response

How to Reproduce?

application.properties:

quarkus.datasource.db-kind=postgresql
quarkus.hibernate-orm.database.generation=drop-and-create

main.java:

//usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS io.quarkus:quarkus-bom:999-SNAPSHOT@pom
//DEPS io.quarkus:quarkus-hibernate-orm-panache
//DEPS io.quarkus:quarkus-resteasy
//DEPS io.quarkus:quarkus-resteasy-jackson
//DEPS io.quarkus:quarkus-jdbc-postgresql
//FILES application.properties

//JAVAC_OPTIONS -parameters

import io.quarkus.hibernate.orm.panache.PanacheEntity;
import io.quarkus.runtime.Quarkus;
import javax.enterprise.context.ApplicationScoped;
import javax.persistence.Entity;
import javax.transaction.Transactional;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.net.URI;
import java.time.LocalDate;
import java.util.List;

@Entity
class Person extends PanacheEntity {
    public String name;
    public LocalDate birth;
    public Status status;

    public static Person findByName(String name){
        return find("name", name).firstResult();
    }

    public static List<Person> findAlive(){
        return list("status", Status.Alive);
    }

    public static void deleteStefs(){
        delete("name", "Stef");
    }
}

enum Status {
    Alive, Dead
}

@Path("/hello-resteasy")
@ApplicationScoped
public class main {

    @GET
    public String sayHello() {
        return "Hello RESTEasy";
    }

    public static void main(String[] args) {
        Quarkus.run(args);
    }

    @Path("/persons")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public class PersonResource {

        @GET
        public List<Person> list() {
            return Person.listAll();
        }

        @GET
        @Path("/{id}")
        public Person get(@PathParam("id") Long id) {
            return Person.findById(id);
        }

        @POST
        @Transactional
        public Response create(Person person) {
            person.persist();
            return Response.created(URI.create("/persons/" + person.id)).build();
        }

        @PUT
        @Path("/{id}")
        @Transactional
        public Person update(@PathParam("id") Long id, Person person) {
            Person entity = Person.findById(id);
            if(entity == null) {
                throw new NotFoundException();
            }

            // map all fields from the person parameter to the existing entity
            entity.name = person.name;

            return entity;
        }

        @DELETE
        @Path("/{id}")
        @Transactional
        public void delete(@PathParam("id") Long id) {
            Person entity = Person.findById(id);
            if(entity == null) {
                throw new NotFoundException();
            }
            entity.delete();
        }

        @GET
        @Path("/search/{name}")
        public Person search(@PathParam("name") String name) {
            return Person.findByName(name);
        }

        @GET
        @Path("/count")
        public Long count() {
            return Person.count();
        }
    }

}

run this with jbang -Dquarkus.dev main.java and go to https://localhost:8080/persons and it trigger the error.

Now change the resteasy to resteasy-reactive:

//DEPS io.quarkus:quarkus-resteasy
//DEPS io.quarkus:quarkus-resteasy-jackson

and restart and it works.

Output of uname -a or ver

No response

Output of java -version

No response

GraalVM version (if different from Java)

No response

Quarkus version or git rev

No response

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

No response

Additional information

No response


https://github.com/quarkusio/quarkus/issues/19757


$upstream:19757$