1 Reply Latest reply on Jul 10, 2012 7:52 AM by Thomas Goettlich

    Intercepting EJB "Bridge" Methods (Generics)

    Thomas Goettlich Novice

      We currently have a problem with bridge methods not being intercepted.

       

      Consider the following case:

       

      //base classes

       

      public class BaseParam {}

       

      public interface BaseInterface<T extends BaseParam> {

         public void doSomething( T param);

      }

       

       

      //specialized classes

       

      public class SpecialParam extends BaseParam{}

       

      public interface SpecialService extends BaseInterface<SpecialParam> {}

       

      @Stateless

      @Local(SpecialService.class)

      @SomeCDIInterceptorBinding

      public class SpecialServiceImpl implements SpecialService {

         public void doSomething( SpecialParam param) {}

      }

       

       

      Now we want to intercept calls to doSomething and register an interceptor for @SomeCDIInterceptorBinding.


      We call the method by using the local interface and thus what is called is doSomething(Param) and not doSomething(SpecialParam).

      The Jsr299BindingsInterceptor thus looks for interceptors on doSomething(Param), which are not registered due to the following line in Beans#getInterceptableMethods(...):

       

      boolean businessMethod = !annotatedMethod.isStatic()

        && !annotatedMethod.isAnnotationPresent(Inject.class)

        && !annotatedMethod.getJavaMember().isBridge();

       

      The bridge method doSomething(Param) in our service is ignored and thus there's no interceptor call.

       

      Note that when the method doSomething(SpecialParam) is added to the SpecialService interface, then not the bridge method but the actual method doSomething(SpecialParam) is called and everything works as expected.

       

       

      So I have several questions:

       

      1. Is this a bug in WELD? I found issue WELD-568 where Marius Bogoevici suggests: " ... provide access to all the methods of the class, including methods which are inherited, but not bridge methods generated for covariants".

      2. Is there a way to work around this? Adding the specialized method override to the sub-interfaces might work in some cases but AFAIK would not work when I call the super interface method.

       

      Thanks in advance for your efforts.