Uploaded image for project: 'Weld'
  1. Weld
  2. WELD-1731

Bogus circular injection warning when injecting two or more fields from same producer

    Details

      Description

      When a bean has two or more fields that are both injected by the same producer, and this producer is exactly created when the bean that is injected is also created, the first field is injected without any issues, but for every other field Weld logs the following bogus warning:

      WELD-000018: Executing producer field or method [BackedAnnotatedMethod] @Produces public test.ProducerBean.produce() on incomplete declaring bean Managed Bean [class test.ProducerBean] with qualifiers [@Any @Default] due to circular injection
      

      The producer:

      @ApplicationScoped
      public class ProducerBean {
      
          @Produces
          public String produce() {
              return "test";
          }
      }
      

      The bean that's injected:

      @ApplicationScoped
      public class AppBean {
      
          @Inject
          private String string1;
          
          @Inject
          private String string2;
          
          public void print() {
              System.out.println("String 1:" + string1 + " String 2:" + string2);
          }
      }
      

      The problem seems to be that when the producer bean is created, an instance is pushed to CreationalContextImpl and ends up there in an incompleteInstances map. The producer bean is then created, the instance returned, and the producer method is called. This all happens correctly.

      However, there is never any code anywhere that pops the instance from the incompleteInstances map, and the CreationalContextImpl that contains this map is re-used again and again, causing any bean that's created during injection to remain marked as an incomplete instance. So when the second field is injected, Weld encounters the producer bean in the incompleteInstances map and therefor assumes there must be a circular dependency, which of course isn't there.

      A full reproducer can be found at https://github.com/arjantijms/weld-bogus-circular

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  Unassigned
                  Reporter:
                  atijms Arjan Tijms
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  2 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: