3 Replies Latest reply on Mar 25, 2014 5:26 AM by mkouba

    Inheritance of annotated methods

    simon.kulessa

      As mentioned in my other ticket I have recently updated our JSF (Trinidad) webapp from weld 1.1.8.Final to 2.1.2.Final.

       

      I have written the following test, that shows that annotated method's from SuperClasses are not considered after the update.

       

      This test is based on the newest Arquillian version with the weld-ee-container,

      which might not support Weld 2.1.2.Final (I've asked this question in the related arquillian forum).

      Regardless the same applies to the real webapp.

       

      The test works fine with weld 1.1.8.Final.

       

      I assume that this scenario is a valid scenario, unlike my other question.

       

      Ps.:

      If someone needs the appropriate dependencies I can post them as well.

       

      ________________________________________

      package test;

       

      import static org.junit.Assert.assertTrue;

       

      import javax.annotation.PostConstruct;

      import javax.enterprise.context.ApplicationScoped;

      import javax.inject.Inject;

       

      import org.jboss.arquillian.container.test.api.Deployment;

      import org.jboss.arquillian.junit.Arquillian;

      import org.jboss.shrinkwrap.api.ArchivePaths;

      import org.jboss.shrinkwrap.api.ShrinkWrap;

      import org.jboss.shrinkwrap.api.asset.ByteArrayAsset;

      import org.jboss.shrinkwrap.api.spec.JavaArchive;

      import org.junit.Test;

      import org.junit.runner.RunWith;

       

      abstract class AbstractClass {

       

          @PostConstruct

          public abstract void init();

      }

       

      @ApplicationScoped

      class Impl extends AbstractClass {

       

          private boolean invoked = false;

       

          public void init() {

              invoked = true;

          }

       

          public boolean isInvoked() {

              return invoked;

          }

      }

       

      @RunWith(Arquillian.class)

      public class ArquillianTest {

       

          @Deployment

          public static JavaArchive createTestArchive() {

              return ShrinkWrap

                      .create(JavaArchive.class, "test.jar")

                      .addClasses(Impl.class)

                      .addAsManifestResource(

                              new ByteArrayAsset(

                                      ("<beans></beans>").getBytes()), ArchivePaths.create("beans.xml"));

          }

       

          @Inject

          Impl impl;

       

          @Test

          public void testInvoke() {

              assertTrue(impl.isInvoked());

          }

      }

        • 1. Re: Inheritance of annotated methods
          mkouba

          Hi Simon,

          the Interceptors 1.2 spec states:

          Lifecycle callback interceptor methods can have public, private, protected, or package level access. A lifecycle callback interceptor method must not be declared as abstract, final or static.

           

          So I believe Weld 2.x is correct. You should either place @PostConstruct annotation on Impl class or use a separate interceptor class (which seems better to me). Also note that if an interceptor method is overridden by another method, it will not be invoked either.

          • 2. Re: Inheritance of annotated methods
            simon.kulessa

            Thanks again for you answer,

            I guess this another 'feature' of the old weld version then

             

            Also note that if an interceptor method is overridden by another method, it will not be invoked either.

            That does not seem to be true. If I just remove the abstract from the superclass init method and replace this with an empty method,

            the init method of the subclass still gets invoked.


            Edit:

            Just forget that - By mistake I tested this with the old weld version

            • 3. Re: Inheritance of annotated methods
              mkouba

              Hm, that's odd. There is a TCK test for this. And here is the corresponding Weld issue: WELD-1225.

               

              Edit:

              What a relief