[cdi-dev] [JBoss JIRA] (CDI-713) Why can't Provider<?> injection points use non-proxyable types with @RequestScoped providers?

Martin Kouba (JIRA) issues at jboss.org
Fri Aug 18 04:25:00 EDT 2017


    [ https://issues.jboss.org/browse/CDI-713?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13451160#comment-13451160 ] 

Martin Kouba commented on CDI-713:
----------------------------------

No, this is not allowed. {{Long getIAT()}} represents a producer method (i.e. bean) and has a normal scope ({{@RequestScope}}). And for an injection point that resolves to a normal scoped bean a client proxy must be injected. For this reason the required bean type must be proxyable. If the given bean type ({{Long}} in this case) cannot be proxied by the container, the container must throw an {{UnproxyableResolutionException}}.

Note that the same rules apply to regular injection and programmatic lookup.

See also [Client proxies|https://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#client_proxies], [Unproxyable bean types|https://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#unproxyable] and  [The Instance interface|https://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#dynamic_lookup].




> Why can't Provider<?> injection points use non-proxyable types with @RequestScoped providers?
> ---------------------------------------------------------------------------------------------
>
>                 Key: CDI-713
>                 URL: https://issues.jboss.org/browse/CDI-713
>             Project: CDI Specification Issues
>          Issue Type: Clarification
>          Components: Portable Extensions, Resolution
>    Affects Versions: 1.2.Final
>         Environment: WildflySwarm 2017.7.0 and Weld 2.4.3.Final.
>            Reporter: Scott Stark
>
> In looking into the use of javax.inject.Provider wrapped injection point values when dealing with @RequestScoped producers:
> {code:java}
>     @Inject
>     @Claim(standard = Claims.iat)
>     private Provider<Long> providerIAT;
> {code}
> {code:java}
>     @Produces
>     @Claim(standard = Claims.iat)
>     @RequestScoped
>     Long getIAT() {
>         JsonWebToken jwt = getJWTPrincpal();
>         if (jwt == null) {
>             System.out.printf("getIAT, null JsonWebToken\n");
>             return null;
>         }
>         System.out.printf("getIAT\n");
>         return jwt.getIssuedAtTime();
>     }
> {code}
> I ran into the following exception:
> {noformat}
> Caused by: org.jboss.weld.exceptions.UnproxyableResolutionException: WELD-001437: Bean type class java.lang.Long is not proxyable because it is final - {2}.
> 	at org.jboss.weld.util.Proxies.getUnproxyableClassException(Proxies.java:218)
> 	at org.jboss.weld.util.Proxies.getUnproxyableTypeException(Proxies.java:182)
> 	at org.jboss.weld.util.Proxies.getUnproxyableTypeException(Proxies.java:144)
> 	at org.jboss.weld.bean.proxy.ClientProxyProvider.getClientProxy(ClientProxyProvider.java:242)
> 	at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:736)
> 	at org.jboss.weld.bean.builtin.InstanceImpl.getBeanInstance(InstanceImpl.java:189)
> 	at org.jboss.weld.bean.builtin.InstanceImpl.get(InstanceImpl.java:100)
> 	at org.eclipse.microprofile.jwt.test.jaxrs.RolesEndpoint.getInjectedIssuer(RolesEndpoint.java:269)
> {noformat}
> The spec is not really clear on why this should happen as the javax.inject.Provider is a proxy for the underlying type. It seems to me that this should be allowed, and that the exception I'm seeing from Weld-2.4.3.Final is a bug, but I wanted to get a clarification on why this might be disallowed.



--
This message was sent by Atlassian JIRA
(v7.2.3#72005)


More information about the cdi-dev mailing list