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

Cannot Inject Configuration Interface into ContainerRequestFilter Through Constructor #8180

Closed
schrieveslaach opened this issue Mar 26, 2020 · 6 comments · Fixed by #8321
Closed
Labels
kind/bug Something isn't working
Milestone

Comments

@schrieveslaach
Copy link

Describe the bug

Injecting configuration interface into ContainerRequestFilter through constructor-based injection creates 500 respones with following error message:

org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException
	at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:381)
	at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:216)
	at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:168)
	at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:245)
	at io.quarkus.resteasy.runtime.standalone.RequestDispatcher.service(RequestDispatcher.java:73)
	at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.dispatch(VertxRequestHandler.java:122)
	at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.access$000(VertxRequestHandler.java:36)
	at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler$1.run(VertxRequestHandler.java:87)
	at io.quarkus.runtime.CleanableExecutor$CleaningRunnable.run(CleanableExecutor.java:231)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
	at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2027)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1551)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1442)
	at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
	at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
	at java.base/java.lang.Thread.run(Thread.java:830)
	at org.jboss.threads.JBossThread.run(JBossThread.java:479)
Caused by: java.lang.NullPointerException
	at org.jboss.resteasy.core.ConstructorInjectorImpl.<init>(ConstructorInjectorImpl.java:54)
	at org.jboss.resteasy.core.InjectorFactoryImpl.createConstructor(InjectorFactoryImpl.java:61)
	at io.quarkus.resteasy.common.runtime.QuarkusInjectorFactory.createConstructor(QuarkusInjectorFactory.java:33)
	at org.jboss.resteasy.core.providerfactory.ResteasyProviderFactoryImpl.injectedInstance(ResteasyProviderFactoryImpl.java:1397)
	at org.jboss.resteasy.core.interception.jaxrs.JaxrsInterceptorRegistryImpl$AbstractInterceptorFactory.createInterceptor(JaxrsInterceptorRegistryImpl.java:150)
	at org.jboss.resteasy.core.interception.jaxrs.JaxrsInterceptorRegistryImpl$OnDemandInterceptorFactory.initialize(JaxrsInterceptorRegistryImpl.java:168)
	at org.jboss.resteasy.core.interception.jaxrs.JaxrsInterceptorRegistryImpl$OnDemandInterceptorFactory.checkInitialize(JaxrsInterceptorRegistryImpl.java:183)
	at org.jboss.resteasy.core.interception.jaxrs.JaxrsInterceptorRegistryImpl$OnDemandInterceptorFactory.getInterceptor(JaxrsInterceptorRegistryImpl.java:194)
	at org.jboss.resteasy.core.interception.jaxrs.JaxrsInterceptorRegistryImpl$AbstractInterceptorFactory.preMatch(JaxrsInterceptorRegistryImpl.java:100)
	at org.jboss.resteasy.core.interception.jaxrs.JaxrsInterceptorRegistryImpl.preMatch(JaxrsInterceptorRegistryImpl.java:263)
	at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:157)

Expected behavior

ContainerRequestFilter should work with construtor-based injection to avoid warnings:

Found unrecommended usage of private members (use package-private instead) in application beans:

However, if I add @ApplicationScoped to the filter it works.

It would be nice if quarkus provides some diagnose.

To Reproduce
Steps to reproduce the behavior:

  1. I have a configuration interface (as described here):
@ConfigProperties
public interface SomeConfiguration {}
  1. And I want to inject it into a ContainerRequestFilter:
@Provider
@PreMatching
public class SomeFilter implements ContainerRequestFilter {

    private final SomeConfiguration configuration;

    @Inject
    public SomeFilter( SomeConfiguration configuration ) {
        this.configuration = configuration;
    }

}
  1. Run the application and make a request

Environment (please complete the following information):

  • Output of uname -a or ver: Darwin Kernel Version 19.0.0: Thu Oct 17 16:17:15 PDT 2019; root:xnu-6153.41.3~29/RELEASE_X86_64 x86_64
  • Output of java -version: openjdk version "13.0.2" 2020-01-14
  • Quarkus version or git rev: 1.3.0
  • Build tool (ie. output of mvnw --version or gradlew --version): mvn 3.6.1
@schrieveslaach schrieveslaach added the kind/bug Something isn't working label Mar 26, 2020
@geoand
Copy link
Contributor

geoand commented Mar 26, 2020

Let me check this

@geoand
Copy link
Contributor

geoand commented Mar 26, 2020

@mkouba @gsmet do you remember what @Provider are not @ApplicationScoped by default?

@mkouba
Copy link
Contributor

mkouba commented Mar 26, 2020

AFAIK they're @Singleton by default as there was no reason to force proxies there?

@mkouba
Copy link
Contributor

mkouba commented Mar 26, 2020

However, I'm not sure whether we support constructor injection on providers...

@geoand
Copy link
Contributor

geoand commented Mar 26, 2020

AFAIK they're @singleton by default as there was no reason to force proxies there?

Makes sense

However, I'm not sure whether we support constructor injection on providers...

Yeah, it doesn't work that well. RESTEasy isn't playing nice with us, so I wonder if we should just warn (or fail) at build time...

@schrieveslaach
Copy link
Author

I wonder if we should just warn (or fail) at build time...

That would work for me and would have helped much faster then the runtime error. 👍

geoand added a commit to geoand/quarkus that referenced this issue Apr 1, 2020
geoand added a commit to geoand/quarkus that referenced this issue Apr 1, 2020
mkouba added a commit that referenced this issue Apr 2, 2020
Add warning about @Provider constructors
@gsmet gsmet added this to the 1.4.0 milestone Apr 7, 2020
viniciusfcf pushed a commit to viniciusfcf/quarkus-fork that referenced this issue Sep 7, 2020
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