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

Constructor injection in JAX-RS Resource which implements an interface causes an RuntimeException #10430

Closed
florianRieb opened this issue Jul 2, 2020 · 7 comments · Fixed by #10446
Labels
kind/bug Something isn't working
Milestone

Comments

@florianRieb
Copy link

Describe the bug
Constructor injection in an RX-Resource class, which implements an interface raise an RuntimeException.
The Resource class contains methods to handle the requests and the interface contains all openapi annotations.

Expected behavior
Constructor injection also work like the field injection.

Actual behavior
On startup:
Caused by: java.lang.RuntimeException: RESTEASY003190: Could not find constructor for class: xx.xxx.IncidentResource

To Reproduce
Steps to reproduce the behavior:

Interface for api doc

@Path("/xxx")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
public interface MyResourceDoc {

  @Path("/{id}")
  @PUT
  @APIResponses({
      @APIResponse(
          responseCode = "201",
          description = "",
          headers = @Header(name = "Location", description = ""),
          content = @Content(
              schema = @Schema(
                  type = SchemaType.OBJECT,
                  implementation = TO.class))),
      @APIResponse(responseCode = "204", description = ""),
      @APIResponse(
          responseCode = "400",
          description = "",
          content = @Content(
              schema = @Schema(
                  type = SchemaType.OBJECT,
                  implementation = ErrorTO.class))) })
  public Response createOrUpdate(
   @PathParam("id") final String id,
   @NotNull @Valid final TO to);

}

Resource class

@Slf4j
@RequiredArgsConstructor
public class MyResource implements MyResourceDoc {
 
  private final  MyService service;

  @Override
  public Response createOrUpdate(
      final String id,
      final TO to) {...}
java.lang.RuntimeException: java.lang.RuntimeException: RESTEASY003190: Could not find constructor for class: xxx.web.MyResource
	at io.quarkus.dev.appstate.ApplicationStateNotification.waitForApplicationStart(ApplicationStateNotification.java:51)
	at io.quarkus.runner.bootstrap.StartupActionImpl.runMainClass(StartupActionImpl.java:155)
	at io.quarkus.deployment.dev.IsolatedDevModeMain.firstStart(IsolatedDevModeMain.java:95)
	at io.quarkus.deployment.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:301)
	at io.quarkus.deployment.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:42)
	at io.quarkus.bootstrap.app.CuratedApplication.runInCl(CuratedApplication.java:131)
	at io.quarkus.bootstrap.app.CuratedApplication.runInAugmentClassLoader(CuratedApplication.java:84)
	at io.quarkus.deployment.dev.DevModeMain.start(DevModeMain.java:126)
	at io.quarkus.deployment.dev.DevModeMain.main(DevModeMain.java:56)
Caused by: java.lang.RuntimeException: RESTEASY003190: Could not find constructor for class: xxx.web.MyResource
	at org.jboss.resteasy.spi.metadata.ResourceBuilder.getConstructor(ResourceBuilder.java:852)
	at org.jboss.resteasy.plugins.server.resourcefactory.POJOResourceFactory.registered(POJOResourceFactory.java:59)
	at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:246)
	at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:227)
	at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:208)
	at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:192)
	at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:175)
	at org.jboss.resteasy.core.ResourceMethodRegistry.addPerRequestResource(ResourceMethodRegistry.java:87)
	at org.jboss.resteasy.core.ResteasyDeploymentImpl.registerResources(ResteasyDeploymentImpl.java:513)
	at org.jboss.resteasy.core.ResteasyDeploymentImpl.registration(ResteasyDeploymentImpl.java:470)
	at org.jboss.resteasy.core.ResteasyDeploymentImpl.startInternal(ResteasyDeploymentImpl.java:160)
	at org.jboss.resteasy.core.ResteasyDeploymentImpl.start(ResteasyDeploymentImpl.java:117)
	at io.quarkus.resteasy.runtime.standalone.ResteasyStandaloneRecorder.staticInit(ResteasyStandaloneRecorder.java:86)
	at io.quarkus.deployment.steps.ResteasyStandaloneBuildStep$staticInit-210558872.deploy_0(ResteasyStandaloneBuildStep$staticInit-210558872.zig:1019)
	at io.quarkus.deployment.steps.ResteasyStandaloneBuildStep$staticInit-210558872.deploy(ResteasyStandaloneBuildStep$staticInit-210558872.zig:36)
	at io.quarkus.runner.ApplicationImpl.<clinit>(ApplicationImpl.zig:218)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
	at java.base/java.lang.Class.newInstance(Class.java:584)
	at io.quarkus.runtime.Quarkus.run(Quarkus.java:60)
	at io.quarkus.runtime.Quarkus.run(Quarkus.java:38)
	at io.quarkus.runtime.Quarkus.run(Quarkus.java:106)
	at io.quarkus.runner.GeneratedMain.main(GeneratedMain.zig:29)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at io.quarkus.runner.bootstrap.StartupActionImpl$3.run(StartupActionImpl.java:144)
	at java.base/java.lang.Thread.run(Thread.java:834)


The field injection works as expected:

@Slf4j
public class MyResource implements MyResourceDoc {

  @Inject
  private  MyService service;

  @Override
  public Response createOrUpdate(
      final String id,
      final final TO to) {...}

Configuration

**Environment (please complete the following information):**
 - Output of `uname -a` or `ver`: 
   Linux fri-VBox 5.4.0-39-generic #43-Ubuntu SMP Fri Jun 19 10:28:31 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
 - Output of `java -version`: 
   openjdk version "11.0.7" 2020-04-14
   OpenJDK Runtime Environment GraalVM CE 20.1.0 (build 11.0.7+10-jvmci-20.1-b02)
   OpenJDK 64-Bit Server VM GraalVM CE 20.1.0 (build 11.0.7+10-jvmci-20.1-b02, mixed mode, sharing)

 - Quarkus version or git rev: 1.5.1.Final
 - Build tool (ie. output of `mvnw --version` or `gradlew --version`):  Apache Maven 3.6.3
   Maven home: /usr/share/maven
   Java version: 11.0.7, vendor: GraalVM Community, runtime: /home/fri/.sdkman/candidates/java/20.1.0.r11-grl
   Default locale: en_US, platform encoding: UTF-8
   OS name: "linux", version: "5.4.0-39-generic", arch: "amd64", family: "unix"
@florianRieb florianRieb added the kind/bug Something isn't working label Jul 2, 2020
@geoand geoand changed the title Constructor injection in RX-Resourcewhich implements an interface causes an RuntimeException Constructor injection in JAX_RS Resource which implements an interface causes an RuntimeException Jul 3, 2020
@geoand geoand changed the title Constructor injection in JAX_RS Resource which implements an interface causes an RuntimeException Constructor injection in JAX-RS Resource which implements an interface causes an RuntimeException Jul 3, 2020
@geoand
Copy link
Contributor

geoand commented Jul 3, 2020

I am pretty sure that the reason this is happening isn't because of the interface, but because of the lombok annotation.
Can you remove them test again please?

@florianRieb
Copy link
Author

I got the same exception with the following code, where I removed all annotations.

public class MyResource implements MyResourceDoc {
  
  private MyService service;

  @Inject
  MyResource(final MyService service){
    this.service = service;
  }

@geoand
Copy link
Contributor

geoand commented Jul 3, 2020

Can you please upload your code to github so I can try it?

I haven't been able to reproduce that error

@florianRieb
Copy link
Author

If clone the following repo and run "mvn quarkus:dev" you should get the same exception.
https://github.com/florianRieb/injection-bug-reproduction.git

Thanks a lot fore your time

geoand added a commit to geoand/quarkus that referenced this issue Jul 3, 2020
geoand added a commit to geoand/quarkus that referenced this issue Jul 3, 2020
@geoand
Copy link
Contributor

geoand commented Jul 3, 2020

Thanks for the reproducer. I added another commit to #10446 that handles your use case

geoand added a commit that referenced this issue Jul 3, 2020
Stop lombok annotations from preventing no-args ctor generation
oztimpower pushed a commit to oztimpower/quarkus that referenced this issue Jul 4, 2020
oztimpower pushed a commit to oztimpower/quarkus that referenced this issue Jul 4, 2020
@gsmet gsmet added this to the 1.6.1.Final milestone Jul 16, 2020
gsmet pushed a commit to gsmet/quarkus that referenced this issue Jul 16, 2020
gsmet pushed a commit to gsmet/quarkus that referenced this issue Jul 16, 2020
@mageddo
Copy link

mageddo commented Aug 9, 2020

Is it supposed to be fixed on 1.6.1.Final? I'm using this version and still having the issue, here a sample

@mageddo
Copy link

mageddo commented Aug 9, 2020

Explicitly add a NonArg constructor fixes the problem, I expect Quarkus to solve it for me though

@Tag(name = "hello-samples")
@Path("/hello")
public class FruitResource {

    HelloService helloService;

    public FruitResource() {
    }

    @Inject
    public FruitResource(HelloService helloService) {
        this.helloService = helloService;
    }
....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants