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

Injection error in start with 1.7.CR1 #11136

Closed
pilhuhn opened this issue Jul 31, 2020 · 9 comments · Fixed by #11196
Closed

Injection error in start with 1.7.CR1 #11136

pilhuhn opened this issue Jul 31, 2020 · 9 comments · Fixed by #11196
Labels
area/arc Issue related to ARC (dependency injection) kind/bug Something isn't working
Milestone

Comments

@pilhuhn
Copy link
Contributor

pilhuhn commented Jul 31, 2020

check out https://github.com/RedHatInsights/policies-ui-backend , do mvn clean test -> all good with 1.6.0 (and all versions before)

Now replace in pom. xml the 1.6.Final with 1.7.CR1 -> the above fails. Run with mvn quarkus:dev, the following is printed at startup:

2020-07-31 22:00:38,141 ERROR [io.qua.run.boo.StartupActionImpl] (Quarkus Main Thread) Error running Quarkus: java.lang.reflect.InvocationTargetException
        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:145)
        at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.ExceptionInInitializerError
        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)
        ... 6 more
Caused by: java.lang.RuntimeException: Failed to start quarkus
        at io.quarkus.runner.ApplicationImpl.<clinit>(ApplicationImpl.zig:436)
        ... 15 more
Caused by: java.lang.RuntimeException: Error injecting com.redhat.cloud.policies.app.RbacServer com.redhat.cloud.policies.app.auth.RbacFilter.rbac
        at com.redhat.cloud.policies.app.auth.RbacFilter_Bean.create(RbacFilter_Bean.zig:376)
        at com.redhat.cloud.policies.app.auth.RbacFilter_Bean.create(RbacFilter_Bean.zig:528)
        at io.quarkus.arc.impl.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:88)
        at io.quarkus.arc.impl.ComputingCache$CacheFunction.lambda$apply$0(ComputingCache.java:99)
        at io.quarkus.arc.impl.LazyValue.get(LazyValue.java:26)
        at io.quarkus.arc.impl.ComputingCache.getValue(ComputingCache.java:41)
        at io.quarkus.arc.impl.AbstractSharedContext.get(AbstractSharedContext.java:25)
        at com.redhat.cloud.policies.app.auth.RbacFilter_Bean.get(RbacFilter_Bean.zig:560)
        at com.redhat.cloud.policies.app.auth.RbacFilter_Bean.get(RbacFilter_Bean.zig:576)
        at io.quarkus.arc.impl.ArcContainerImpl.beanInstanceHandle(ArcContainerImpl.java:408)
        at io.quarkus.arc.impl.ArcContainerImpl.beanInstanceHandle(ArcContainerImpl.java:421)
        at io.quarkus.arc.impl.ArcContainerImpl$1.get(ArcContainerImpl.java:249)
        at io.quarkus.arc.impl.ArcContainerImpl$1.get(ArcContainerImpl.java:246)
        at io.quarkus.arc.runtime.ArcRecorder$2$1.create(ArcRecorder.java:84)
        at io.quarkus.resteasy.common.runtime.QuarkusConstructorInjector.construct(QuarkusConstructorInjector.java:39)
        at org.jboss.resteasy.core.providerfactory.ResteasyProviderFactoryImpl.injectedInstance(ResteasyProviderFactoryImpl.java:1398)
        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.postMatch(JaxrsInterceptorRegistryImpl.java:131)
        at org.jboss.resteasy.core.interception.jaxrs.JaxrsInterceptorRegistryImpl.postMatch(JaxrsInterceptorRegistryImpl.java:283)
        at org.jboss.resteasy.core.interception.jaxrs.ContainerRequestFilterRegistryImpl.postMatch(ContainerRequestFilterRegistryImpl.java:30)
        at org.jboss.resteasy.core.interception.jaxrs.ContainerRequestFilterRegistryImpl.postMatch(ContainerRequestFilterRegistryImpl.java:12)
        at org.jboss.resteasy.core.ResourceMethodInvoker.<init>(ResourceMethodInvoker.java:140)
        at org.jboss.resteasy.core.ResourceMethodRegistry.processMethod(ResourceMethodRegistry.java:382)
        at org.jboss.resteasy.core.ResourceMethodRegistry.register(ResourceMethodRegistry.java:309)
        at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:260)
        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:515)
        at org.jboss.resteasy.core.ResteasyDeploymentImpl.registration(ResteasyDeploymentImpl.java:472)
        at org.jboss.resteasy.core.ResteasyDeploymentImpl.startInternal(ResteasyDeploymentImpl.java:162)
        at org.jboss.resteasy.core.ResteasyDeploymentImpl.start(ResteasyDeploymentImpl.java:118)
        at io.quarkus.resteasy.runtime.standalone.ResteasyStandaloneRecorder.staticInit(ResteasyStandaloneRecorder.java:71)
        at io.quarkus.deployment.steps.ResteasyStandaloneBuildStep$staticInit-210558872.deploy_0(ResteasyStandaloneBuildStep$staticInit-210558872.zig:810)
        at io.quarkus.deployment.steps.ResteasyStandaloneBuildStep$staticInit-210558872.deploy(ResteasyStandaloneBuildStep$staticInit-210558872.zig:40)
        at io.quarkus.runner.ApplicationImpl.<clinit>(ApplicationImpl.zig:394)
        ... 15 more
Caused by: javax.enterprise.inject.CreationException: Synthetic bean instance not initialized yet: org_eclipse_microprofile_context_ManagedExecutor_97d170e1550eee4afc0af065b78cda302a97674c
        at org.eclipse.microprofile.context.ManagedExecutor_29efa7b6c09f5f806580e59c31b0b9832488e1e4_Synthetic_Bean.create(ManagedExecutor_29efa7b6c09f5f806580e59c31b0b9832488e1e4_Synthetic_Bean.zig:115)
        at org.eclipse.microprofile.context.ManagedExecutor_29efa7b6c09f5f806580e59c31b0b9832488e1e4_Synthetic_Bean.create(ManagedExecutor_29efa7b6c09f5f806580e59c31b0b9832488e1e4_Synthetic_Bean.zig:138)
        at io.quarkus.arc.impl.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:88)
        at io.quarkus.arc.impl.ComputingCache$CacheFunction.lambda$apply$0(ComputingCache.java:99)
        at io.quarkus.arc.impl.LazyValue.get(LazyValue.java:26)
        at io.quarkus.arc.impl.ComputingCache.getValue(ComputingCache.java:41)
        at io.quarkus.arc.impl.AbstractSharedContext.get(AbstractSharedContext.java:25)
        at org.eclipse.microprofile.context.ManagedExecutor_29efa7b6c09f5f806580e59c31b0b9832488e1e4_Synthetic_Bean.get(ManagedExecutor_29efa7b6c09f5f806580e59c31b0b9832488e1e4_Synthetic_Bean.zig:170)
        at org.eclipse.microprofile.context.ManagedExecutor_29efa7b6c09f5f806580e59c31b0b9832488e1e4_Synthetic_Bean.get(ManagedExecutor_29efa7b6c09f5f806580e59c31b0b9832488e1e4_Synthetic_Bean.zig:186)
        at io.quarkus.arc.impl.ArcContainerImpl.beanInstanceHandle(ArcContainerImpl.java:408)
        at io.quarkus.arc.impl.ArcContainerImpl.beanInstanceHandle(ArcContainerImpl.java:421)
        at io.quarkus.arc.impl.ArcContainerImpl.instanceHandle(ArcContainerImpl.java:391)
        at io.quarkus.arc.impl.ArcContainerImpl.instance(ArcContainerImpl.java:205)
        at io.quarkus.restclient.runtime.RestClientBase.create(RestClientBase.java:60)
        at com.redhat.cloud.policies.app.RbacServer_175c6127e4261f4f0b6cddf18a2ed3ab43163b13_Synthetic_Bean.create(RbacServer_175c6127e4261f4f0b6cddf18a2ed3ab43163b13_Synthetic_Bean.zig:188)
        at com.redhat.cloud.policies.app.RbacServer_175c6127e4261f4f0b6cddf18a2ed3ab43163b13_Synthetic_Bean.get(RbacServer_175c6127e4261f4f0b6cddf18a2ed3ab43163b13_Synthetic_Bean.zig:219)
        at com.redhat.cloud.policies.app.RbacServer_175c6127e4261f4f0b6cddf18a2ed3ab43163b13_Synthetic_Bean.get(RbacServer_175c6127e4261f4f0b6cddf18a2ed3ab43163b13_Synthetic_Bean.zig:242)
        at io.quarkus.arc.impl.CurrentInjectionPointProvider.get(CurrentInjectionPointProvider.java:52)
        at com.redhat.cloud.policies.app.auth.RbacFilter_Bean.create(RbacFilter_Bean.zig:359)
        ... 55 more


@pilhuhn pilhuhn added the kind/bug Something isn't working label Jul 31, 2020
@quarkusbot
Copy link

/cc @mkouba, @manovotn

@quarkusbot quarkusbot added the area/arc Issue related to ARC (dependency injection) label Jul 31, 2020
@gsmet gsmet added this to the 1.7.0.Final milestone Jul 31, 2020
@geoand
Copy link
Contributor

geoand commented Aug 1, 2020

Perhaps related to #10985 ?

@stuartwdouglas
Copy link
Member

A workaround is to add @ApplicationScoped to com.redhat.cloud.policies.app.RbacServer.

@mkouba
Copy link
Contributor

mkouba commented Aug 3, 2020

Stuart is right. The RbacServer rest client is injected into the RbacFilter which is created eagerly before the app starts (STATIC_INIT) and since rest client beans are @Dependent by default the rest client instance is created eagerly. So if you annotate the RbacServer with @ApplicationScoped it's not created until it's really used.

However, if it fails now then it means that before 1.7.0.CR1 the ManagedExecutor was always null, i.e. no context was propagated to the async client threads.

@pilhuhn
Copy link
Contributor Author

pilhuhn commented Aug 3, 2020

I can confirm, that the workaround works.

But as @mkouba says, the Rest-Client-Interface is @Dependent by default (in the MP-Spec), I would not advise to require @ApplicationScoped.

@mkouba
Copy link
Contributor

mkouba commented Aug 3, 2020

Another workaround could be to inject @WithCaching @RestClient Instance<RbacServer> and rbac.get() instead. This way a single @Dependent instance is created lazily and cached for all invocations.

@geoand
Copy link
Contributor

geoand commented Aug 3, 2020

Could any of these workarounds be baked into the error message? Because currently the error has almost no call to action

@pilhuhn
Copy link
Contributor Author

pilhuhn commented Aug 3, 2020

@geoand Or perhaps just be applied under the hood in all the synthetic code that is produced?
I think people look at the MP specs and/or even want to port software over. Having to apply stuff that is not in the spec may come as a surprise or could be seen as UX issue.

@geoand
Copy link
Contributor

geoand commented Aug 3, 2020

The approach we are currently thinking of (discussed in https://quarkusio.zulipchat.com/#narrow/stream/187038-dev/topic/Injection.20error) is to make REST Client beans @ApplicationScoped by default

mkouba added a commit to mkouba/quarkus that referenced this issue Aug 4, 2020
mkouba added a commit to mkouba/quarkus that referenced this issue Aug 4, 2020
mkouba added a commit to mkouba/quarkus that referenced this issue Aug 4, 2020
@gsmet gsmet modified the milestones: 1.7.0.Final, 1.7.0.CR2 Aug 4, 2020
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) kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants