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

    Circular Injection causes Null Pointers: bug or limitation?

    Tim Evers Master

      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.