tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gonçalo Marques (JIRA) <>
Subject [jira] [Created] (OPENEJB-2125) CDI extension that wraps an InjectionTarget (JAX-RS) causes a ClassCastException
Date Tue, 05 Jan 2016 00:18:39 GMT
Gonçalo Marques created OPENEJB-2125:

             Summary: CDI extension that wraps an InjectionTarget (JAX-RS) causes a ClassCastException
                 Key: OPENEJB-2125
             Project: OpenEJB
          Issue Type: Bug
          Components: integration, tomee
    Affects Versions: (not version related)
            Reporter: Gonçalo Marques

If an arbitrary CDI extension wraps a {{InjectionTarget}} during {{@Observes ProcessInjectionTarget<T>}}
event, it will result in a {{ClassCastException}} in TomEE JAX-RS service startup.


// InjectionTarget wrapper
public class InjectionTargetWrapper<T> implements InjectionTarget<T>
    private final InjectionTarget<T> wrapped;
    public InjectionTargetWrapper(InjectionTarget<T> injectionTarget){
        this.wrapped = injectionTarget;

    // All InjectionTarget interface methods
    // delegate to the wrapped instance and 
    // decorate the wrapped instance 
    // implementation where needed


// CDI extension
public class SomeExtension implements Extension {

    <T> void processInjectionTarget(@Observes ProcessInjectionTarget<T> pit, BeanManager
beanManager) {
        InjectionTarget<T> it = pit.getInjectionTarget();
        pit.setInjectionTarget(new InjectionTargetWrapper<T>(it);

With the aforementioned wrapping, any existing CDI managed JAX-RS endpoint that is processed
by the CDI extension will have its {{InjectionTarget}} changed to the wrapper type: {{InjectionTargetWrapper}}.

This results in a {{ClassCastException}} during TomEE JAX-RS service startup, more precisely
in {{ Class<?>

This method will be called by the CXF application deployment while processing the JAX-RS endpoint
bean and will cast the bean {{InjectionTarget}} to {{InjectionTargetImpl}}. Since the JAX-RS
bean {{InjectionTarget}} has been changed to the wrapper - of type {{InjectionTargetWrapper}}
- this results in a {{ClassCastException}}.

This has been originally reported [at GitHub|].
The specific CDI extension class may also be found at GitHub [com.byteslounge.cdi.extension.PropertyExtension|].

While the just mentioned extension is more complex than the initial example described in this
issue, this problem will occur for every CDI extension that happens to process and change
a JAX-RS endpoint {{InjectionTarget}} to another type, ex: a wrapper (if the wrapper itself
does not inherit from OpenWebBeans {{InjectionTargetImpl}} of course, but this is not likely
to happen for the obvious reasons).

I will attach a very simple ready-to-build project that demonstrates the issue. The project
has a JAX-RS endpoint and includes the aforementioned CDI extension. The problem will immediately
occur if the application is deployed in TomEE JAX-RS v1.7.3

This message was sent by Atlassian JIRA

View raw message