2 Replies Latest reply on Jul 27, 2012 5:39 AM by woelfle

    Synthetic method passed in InvocationContext

    woelfle

      We have a JEE interceptor that validates method calls using the MethodValidator from the hibernate-validator package. We are running into problems when generic methods on stateless session beans are called that have been overwritten in a subclass. The problem is that the InvocationContext passed into our interceptor references the synthetic bridge method generated by the compiler instead of the correct overwritten method. Synthetic methods are ignored by hibernate-validator (see BeanMetaDataImpl.initMethodConstraints). This results in a NullPointerException when hibernate-validator tries to validate the given synthetic bridge method.

       

      Environment:

       

      JBoss AS 7.2.0.Alpha1

      Java 6

       

       

      Code example:

       

      public interface CrudService<D extends PersistentElement> {

        D elementById(long id);

      }

       

      @Local

      public interface AccountService extends CrudService<Account> {

        ... some additional methods

      }

       

      public class AbstractCrudServiceImpl<D extends PersistentElement> implements CrudService<D> {

        public D elementById(long id) {

           ... do something

        }

      }

       

      @Stateless

      public class AccountServiceImpl extends AbstractCrudServiceImpl<Account> implements AccountService {

        @Override

        public Account elementById(long id) {

          ... a specialized implementation

        }

      }

       

      public class SomeOtherSessionBean {

        @Inject

        private AccountService accountService;

       

        public void doSomething() {

          accountService.elementById(1);

        }

      }

       

       

      In the example code above 'SomeOtherSessionBean.doSomething()' calls the method 'elementById'. In that case the InvocationContext passed into our interceptor references the synthetic bridge method with the signature 'PersistentElement AccountServiceImpl.elementById(long)' instead of the concrete method 'Account AccountServiceImpl.elementById(long)'.

       

      This seems to be a bug, isn't it?