Uploaded image for project: 'CDI TCK'
  1. CDI TCK
  2. CDITCK-140

TCK uses cyclic @PostConstruct calls which is forbidden by JSR-250

    Details

      Description

      from JSR-250-1.1.MREL section 2.5:
      "The PostConstruct annotation is used on a method that needs to be executed after
      dependency injection is done to perform any initialization. This method MUST be
      invoked before the class is put into service."

      Which I read as "may only get used by others after the @PostConstruct annotated method did run".

      This is backed by the following example

      public BeanA {
      private @Inject BeanB b;
      private int x = 0;
      public int getX()

      { return x; }
      @PostConstruct void init() { x = b.getX()+7; }
      }

      public BeanB {
      private @Inject BeanA a;
      private int x = 0;
      public int getX() { return x; }

      @PostConstruct void init()

      { x = a.getX()+9; }

      }

      which value do a.x and b.x get finally? This would simply be non-deterministic - and therefore forbidden by the JSR-250 spec.

      Such kind of circular @PostConstruct method calls happen e.g. in CircularDependencyTest Pig -> Food -> Pig

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  dallen6 David Allen
                  Reporter:
                  struberg Mark Struberg
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: