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

Maven Multi module CDI Injection_ClientProxy ClassCastException #2319

Closed
klebeer opened this issue May 1, 2019 · 9 comments · Fixed by #2332
Closed

Maven Multi module CDI Injection_ClientProxy ClassCastException #2319

klebeer opened this issue May 1, 2019 · 9 comments · Fixed by #2332
Assignees
Milestone

Comments

@klebeer
Copy link

klebeer commented May 1, 2019


This is a simple project to reproduce a bug (or a misunderstood of how quarkus dev works)

https://github.com/klebeer/quarkus-bug

Environment:

  • Oracle jdk1.8.0_211
  • OS name: "mac os x", version: "10.14.4", arch: "x86_64", family: "mac"
  • Apache Maven 3.6.0
  • Quarkus 0.14.0

I have a maven multi-module project, one project is an "API" with only interfaces.
The second project is the "API Implementation", this project contains a Bean with @ApplicationScoped annotation.
The third project is a Rest Resource injecting with CDI the "API".

main-project
  -api
  -api-impl
  -rest

In the rest layer, there is a CDI injection of this "API"

   @Inject
   HelloService helloService;


    @GET
    @Produces(MediaType.TEXT_PLAIN)
    @Path("/{name}")
    public String hello(@PathParam("name") String name) {
        return helloService.sayHello(name);
    }
    

Steps to reproduce:

mvn clean install
cd buggy-app/
 mvn compile quarkus:dev
 curl http://127.0.0.1:8080/hello/hello-bug      

Calling this uri, we have a java.lang.ClassCastException: l_ClientProxy cannot be cast to

Caused by: java.lang.ClassCastException: org.ecuadorjug.api.impl.HelloServiceImpl_ClientProxy cannot be cast to org.ecuadorjug.api.HelloService
        at org.ecuadorjug.app.HelloResource_Bean.create(Unknown Source)
        at org.ecuadorjug.app.HelloResource_Bean.create(Unknown Source)
        at io.quarkus.arc.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:86)
        at io.quarkus.arc.AbstractSharedContext.lambda$new$0(AbstractSharedContext.java:33)
@gsmet
Copy link
Member

gsmet commented May 2, 2019

@mkouba can you take a look?

@mkouba mkouba self-assigned this May 3, 2019
@mkouba
Copy link
Contributor

mkouba commented May 3, 2019

So the problem only occurs in the dev mode. It seems that HelloService (from the api jar) loaded for an application wiring class (HelloResource_Bean) is different from the the HelloService loaded for a framework class (HelloServiceImpl_ClientProxy; note that HelloServiceImpl and relevant bean metadata are considered fwk constructs because the classes come from non-app maven modules).

@stuartwdouglas I would expect the HelloService to be loaded by the parent/fwk class loader, or?

@mkouba
Copy link
Contributor

mkouba commented May 3, 2019

Ok. I didn't know we do support quarkus:dev in multimodule projects but it seems the support does not count with the generated wiring classes. In other words, when ArC generates a bean from a dependent module it has no way to detect a class from a multimodule project and thus the bean class is loaded as a framework class.

@mkouba
Copy link
Contributor

mkouba commented May 3, 2019

I have a solution for ArC and I'm going to send a PR shortly but basically any integration that generates wiring classes for both the application and framework classes could be affected.

@klebeer
Copy link
Author

klebeer commented May 3, 2019

thanks! it works perfectly

@InfoSec812
Copy link
Contributor

I am seeing this on Quarkus 1.0.1.Final, so perhaps a regression?

Reproducing example here: https://github.com/InfoSec812/quarkus-openapi-todo-demo/tree/switch-to-maven-multimodule

@gsmet
Copy link
Member

gsmet commented Dec 5, 2019

@InfoSec812 could you open a new issue? Thanks!

@gsmet
Copy link
Member

gsmet commented Dec 5, 2019

Please detail how we can reproduce your issue.

@InfoSec812
Copy link
Contributor

Please detail how we can reproduce your issue.

@gsmet Issue is here: #5970

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