8 Replies Latest reply on Nov 8, 2013 9:06 AM by mkouba

    Injection depends on visibility of class/methdod. A bug?

    matinh

      Hi!

       

      In my sample project the dependency injection doesn't work for special combinations of class-/method-visibility, which very much seems like a bug in weld to me. Maybe someone could explain the observed behavior to me.

       

      Here is what I have:

       

      • A simple, session-scoped, managed bean, that derives from an abstract base-class:
      MyFirstBean.java

      @Named

      @SessionScoped

      public class MyFirstBean extends MyAbstractBean implements Serializable

      {

      }

       

      • The package private abstract base class for the bean with some injections:

       

      MyAbstraceBean.java

      abstract class MyAbstractBean

      {

          @Inject

          public void setFoo(Double f)

          {

              System.out.println("## foo injected: " + f);

          }

         

          @Inject

          public void init()

          {

              System.out.println("## MyAbstractBean.init() called");

          }


          public Double getFoo()
          {
              return 1.2d;
          }
      }

       

      • An XHTML that uses the bean, so it definitely gets constructed.

       

      The methods annotated with @Inject are not called in this case! Why not?

       

      As soon as I change the visibility of the abstract class from package-private to public or the method visibility to package-private everything works as expected. Neither in the JSR-299 specification nor in the seam manual there is anything available that mentions visibility. Did I find a bug?

       

      My environment:

      • JBoss AS 7.1.1
      • JEE 6
      • Weld 1.1.16

       

      Many thanks in advance,

      - martin