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

2.14.0.CR1 Class with @Provider and @RequestScoped annotations causes build failure #28889

Closed
bcluap opened this issue Oct 27, 2022 · 25 comments · Fixed by #28946
Closed

2.14.0.CR1 Class with @Provider and @RequestScoped annotations causes build failure #28889

bcluap opened this issue Oct 27, 2022 · 25 comments · Fixed by #28946
Labels
area/arc Issue related to ARC (dependency injection) area/rest
Milestone

Comments

@bcluap
Copy link

bcluap commented Oct 27, 2022

When changing from 2.13.3.Final to 2.14.0.CR1 Quarkus build fails on our project:

Failed to execute goal io.quarkus:quarkus-maven-plugin:2.14.0.CR1:build (default) on project eclipse-deployable: Failed to build quarkus application: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
	[error]: Build step io.quarkus.arc.deployment.ArcProcessor#validate threw an exception: javax.enterprise.inject.spi.DeploymentException: Found 304 deployment problems: 
[1] Unsatisfied dependency for type com.ukheshe.arch.rest.RequestContext and qualifiers [@Default]
	- java member: com.ukheshe.services.reporting.aaa.BaseReportingGateKeeper#context
	- declared on CLASS bean [types=[com.ukheshe.arch.aaa.GateKeeper, com.ukheshe.arch.impl.aaa.SourceIpCheckingGateKeeper, com.ukheshe.arch.impl.aaa.RoleBasedGateKeeper, com.ukheshe.services.reporting.aaa.MoneyMessageReportingGateKeeper, com.ukheshe.services.reporting.aaa.BaseReportingGateKeeper, java.lang.Object], qualifiers=[@Default, @Any], target=com.ukheshe.services.reporting.aaa.MoneyMessageReportingGateKeeper]

The full list of errors is huge but all relate to injecting com.ukheshe.arch.rest.RequestContext
The implementation of this class is slightly unique in that it looks like this:

@Provider
@PreMatching
@RequestScoped
@Priority(Priorities.HEADER_DECORATOR + 200)
public class RequestContextImpl implements ContainerRequestFilter, RequestContext {

private ContainerRequestContext containerRequestContext;

@Override
    public void filter(ContainerRequestContext requestContext) throws IOException {
        this.containerRequestContext = requestContext;
    }

If I remove the @Provider annotation then the build succeeds but the application has issues because this class needs to be a ContainerRequestFilter to get the requestContext and use it when this RequestScoped bean is injected.

Not sure if 2.14 has changed something and wont properly process beans that have both @Provider and @RequestScoped

@bcluap bcluap changed the title 2.14.0.CR1 2.14.0.CR1 Class with @Provider and @RequestScoped annotations causes build failure Oct 27, 2022
@gsmet
Copy link
Member

gsmet commented Oct 28, 2022

@bcluap thanks for the report. A reproducer would be welcome.

@bcluap
Copy link
Author

bcluap commented Oct 28, 2022

I'll see what I can do. A bit swamped today but will get something to you

@gsmet
Copy link
Member

gsmet commented Oct 28, 2022

/cc @geoand @mkouba for your awareness

@geoand
Copy link
Contributor

geoand commented Oct 28, 2022

I won't be around until Monday to look at this.

Also cc @Sgitario

@geoand
Copy link
Contributor

geoand commented Oct 28, 2022

Also cc @manovotn who might have made a related change

@bcluap
Copy link
Author

bcluap commented Oct 28, 2022

Reproducer:
git clone [email protected]:bcluap/quarkus-examples.git
cd quarkus-examples/resteasy-reactive
mvn verify

@geoand
Copy link
Contributor

geoand commented Oct 31, 2022

@manovotn this seems to be caused by #28429.

We really need to address this one for 2.14.0.Final, can you please take a look?

Thanks

@gsmet
Copy link
Member

gsmet commented Oct 31, 2022

I will revert it if we can't find a solution by then.

@geoand
Copy link
Contributor

geoand commented Oct 31, 2022

Yeah, that makes perfect sense.

@manovotn
Copy link
Contributor

@manovotn this seems to be caused by #28429.

I am looking at it now; will report back once I know more.

I will revert it if we can't find a solution by then.

Agreed.

@manovotn manovotn added area/arc Issue related to ARC (dependency injection) area/rest labels Oct 31, 2022
@manovotn
Copy link
Contributor

So, the problem lies with this code - https://github.com/quarkusio/quarkus/blob/main/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/ResteasyReactiveProcessor.java#L730-L790

We limit bean types of RestEasy classes (such as those with @Provider) to that of the implementation bean which meets internal needs for typesafe resolution in BeanContainer#beanInstanceFactory that RR uses.
However, in this reproducer, the class is also a user bean implementing custom interface and after our modification, the bean loses this interface as its type for the sake of typesafe resolution.

@bcluap note that the reproducer app can be made to work if you instead inject the exact class, i.e. instead of @Inject RequestContext, you can do @Inject RequestContextImpl and it will work just fine. Alternatively, annotating RequestContextImpl with @Typed({RequestContextImpl.class, RequestContext.class}) will do the trick as well and you can then perform the injection based on the interface type.

I am not yet sure how to fix this. We need type restriction if the instance factory should behave according to CDI rules but that inevitably breaks scenarios such as the one presented here...
Thoughts @mkouba?

@mkouba
Copy link
Contributor

mkouba commented Oct 31, 2022

Well, I'm not sure it's a good idea to use a bean class that implements the ContainerRequestFilter separately, i.e. via @Inject. And the @Typed workaround seems to me reasonable for this particular case.

@manovotn
Copy link
Contributor

Well, I'm not sure it's a good idea to use a bean class that implements the ContainerRequestFilter separately, i.e. via @Inject

I didn't want to judge that because I am not a RE expert so I have no idea if this common case or not; @geoand might know more.
But I do agree this can get weird really fast and not just with types but also with scopes.

As for solutions:

  1. I don't think we can fine-grain how we limit types of beans because we cannot reliably tell which types are "good" and which should be removed
  2. We can revert back to using non-CDI behavior for instance factories (which a revert of the original PR would do)
  3. We can consider this an existing downside of resteasy having providers and resources automatically treated as beans with known workarounds

Personally, I'd lean towards 3. with this case.

@geoand
Copy link
Contributor

geoand commented Oct 31, 2022

Well, I'm not sure it's a good idea to use a bean class that implements the ContainerRequestFilter separately
I didn't want to judge that because I am not a RE expert so I have no idea if this common case or not; @geoand might know more.

Yeah, this is indeed weird - it would only work in Quarkus and not in any other JAX-RS / CDI implementation. It's not something we have ever said we support, it worked previously by accident.

If we are going to disallow this case, #28429 needs to be a breaking change (I added the label)

@manovotn
Copy link
Contributor

With the above comments, unless @geoand or @gsmet are opposed, I'd suggest we close this issue as not a bug with known workaround.

@geoand
Copy link
Contributor

geoand commented Oct 31, 2022

I'd like to hear from @bcluap on the reasoning behind using this particular pattern

@bcluap
Copy link
Author

bcluap commented Oct 31, 2022 via email

@geoand
Copy link
Contributor

geoand commented Oct 31, 2022

Thanks for that info!

Given that this kind of thing is no longer necessary (as RR fuses CDI and JAX-RS seamlessly), I am personally in favor of dropping support for this.

@bcluap
Copy link
Author

bcluap commented Oct 31, 2022 via email

@geoand
Copy link
Contributor

geoand commented Oct 31, 2022

Indeed ContainerRequestContext is not a bean type, so it's not eligible for injection.

But you essentially want to access HttpHeaders, correct?

@bcluap
Copy link
Author

bcluap commented Oct 31, 2022 via email

@bcluap
Copy link
Author

bcluap commented Oct 31, 2022 via email

@geoand
Copy link
Contributor

geoand commented Oct 31, 2022

#28946 will allow you to inject ContainerRequestContext directly

@bcluap
Copy link
Author

bcluap commented Oct 31, 2022 via email

@geoand
Copy link
Contributor

geoand commented Oct 31, 2022

Hahaha ❤️

The community makes all this possible :)

gsmet added a commit that referenced this issue Oct 31, 2022
Add the ability to inject ContainerRequestContext via CDI
@quarkus-bot quarkus-bot bot added this to the 2.15 - main milestone Oct 31, 2022
@gsmet gsmet modified the milestones: 2.15 - main, 2.14.0.Final Nov 1, 2022
gsmet pushed a commit to gsmet/quarkus that referenced this issue Nov 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/arc Issue related to ARC (dependency injection) area/rest
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants