2 Replies Latest reply on Oct 9, 2009 1:15 AM by kragoth

    Circular Injection causes Null Pointers: bug or limitation?

    kragoth

      Hey all,


      I've got the following bit of code.


      UserMaintenanceController class


      ...imports
      
      @Name(UserMaintenanceController.SEAM_ID)
      @Scope(ScopeType.CONVERSATION)
      public class UserMaintenanceController extends AbstractModuleController {
      
          ...other variables
      
          @In(value = NavigationManager.SEAM_ID, required = true)
          private NavigationManager navMan;
      
          @In(value = UserDetailsTabDataBean.SEAM_ID, create = true)
          private UserDetailsTabDataBean detailsTab;
      
          public void gotoUserMaintenance(User user, BackNavigation exitAction) {
              Validate.notNull(exitAction, "param exitAction cannot be null");
              this.exitAction = exitAction;
              this.user = user;
      
              if (user == null) {
                  setFormMode(FormMode.CREATE);
              } else {
                  setFormMode(FormMode.VIEW);
              }
              
              loadUser(); //ALL INJECTED VARIABLES ARE FINE UP TO THIS POINT
              detailsTab.init(); //AFTER THIS LINE navMan IS NULL
              navMan.lockGlobalNavigation();
              navMan.redirectToModule(
                  this.getConversationId(), 
                  USER_DETAILS_URL, 
                  MODULE_BREADCRUMB_ID, 
                  DETAILS_BREADCRUMB_ID);
          }
      
          ...the rest of this class but it doesn't matter.
      }
      



      And then in the UserDetailsTabDataBean class


      ... imports
      
      @Name(UserDetailsTabDataBean.SEAM_ID)
      @Scope(ScopeType.CONVERSATION)
      public class UserDetailsTabDataBean extends AbstractSeamComponent {
      
          ...other variables
      
          @In(value = UserMaintenanceController.SEAM_ID, required=true)
          private UserMaintenanceController userMaintenanceCtrl;
      
          public void init() {
              locations = 
                  listHelper.fetchActivePersistentEntityListAndInclude(
                      Location.class, 
                      userMaintenanceCtrl.getUser().getUserLocation(), 
                      "description");
              
              titles = 
                  listHelper.fetchActivePersistentEntityListAndInclude(
                      Title.class, 
                      userMaintenanceCtrl.getUser().getTitle(), 
                      "description");
      
              districtOffices = 
                  listHelper.fetchActivePersistentEntityListAndInclude(
                      DistrictOffice.class, 
                      userMaintenanceCtrl.getUser().getDefaultDistrictOffice(), 
                      "description");
              
              ranks = Arrays.asList(SecurityRank.values());
              Collections.sort(ranks);
          }
      }
      




      Ok, so whenever I make a call to UserMaintenanceController.gotoUserMaintenance(user, exitAction), I end up with all my Seam injected variables being null. I've marked the line where it happens in the code. It happens when I make a call to another Seam bean that also injects the UserMaintenanceController. So I do have a circular injection path. But, should this cause me to end up with null variables when the call to the other Seam bean is over? I thought I saw somewhere in the Seam codebase some logic that was supposed to stop this from happening (spent a while digging around to learn what was going on).


      I'm running Seam 2.1.0.GA.


      I guess all I want to know is: Should I change my code to get around this problem or is this as bug that I should raise? Because the fix isn't that hard, it's just annoying. I have to extract my navigation methods out to a different Seam bean so that there is no circular injection.

        • 1. Re: Circular Injection causes Null Pointers: bug or limitation?
          kragoth

          Well, the fix isn't as hard as I said earlier, all I had to do was use


          navMan = (NavigationManager) Component.getInstance(NavigationManager.SEAM_ID);
          



          after the call to the other seam bean then my navMan variable worked fine (as expected).
          So the appropriate section of code now looks like this:


              loadUser();
              detailsTab.init();
              navMan = (NavigationManager) Component.getInstance(NavigationManager.SEAM_ID); //Seam has nulled out my variable now, so refresh it
              navMan.lockGlobalNavigation();
              navMan.redirectToModule(
                  this.getConversationId(), 
                  USER_DETAILS_URL, 
                  MODULE_BREADCRUMB_ID, 
                  DETAILS_BREADCRUMB_ID);
          



          I still don't think I should have to do this. Can a Seam person advise if I should raise a Jira, or is this a known and expected limitation?

          • 2. Re: Circular Injection causes Null Pointers: bug or limitation?
            kragoth