7 Replies Latest reply on Jun 15, 2010 7:14 PM by Tim Evers

    Cyclic Dependency Injection

    Philip Murphy Newbie

      Can someone explain what is happening here? I seem to have a cyclic-injection problem where previously injected objects are being nulled out (from the parent class) if a parent class (testA) calls a child class (testB) method where the child needs to inform or get some information from its parent.


      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      
      @Name("testA")
      @Scope(ScopeType.CONVERSATION)
      public class TestA {
           @In(create = true)
           private TestB testB;
           
           public void testBInjection() {
                testB.testAInjection();
                testB.testAInjection(); // java.lang.NullPointerException thrown here
           }
      }
      
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      
      @Name("testB")
      @Scope(ScopeType.CONVERSATION)
      public class TestB {
           @In
           private TestA testA;
           
           public void testAInjection() {
                System.out.println("TestB.testAInjection called, testA: " + testA);
           }
      }
      



      Sample output:


      TestB.testAInjection called, testA: TestA@6777b2a4
      Caused by: java.lang.NullPointerException
              at TestA.testBInjection(TestA.java:16)
      



      jboss-seam-2.2.0.CR1
      jboss-5.1.0.GA-jdk6
      jdk1.6.0_16