Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-73314

Pointless conditional in GroupLocalServiceImpl#doSearch

    Details

      Description

      Description
      In the GroupLocalServiceImpl#doSearch method, there is a pointless conditional that is just wasting space and making the code harder to read.

      This issue is not testable by QA

      Explanation
      At the beginning of the GroupLocalServiceImpl#doSearch method, we have the following code:

      boolean parentGroupIdEquals = true;
      
      if (parentGroupId == GroupConstants.ANY_PARENT_GROUP_ID) {
      	parentGroupIdEquals = false;
      }
      

      Essentially, we're setting parentGroupIdEquals to false if parentGroupId is -1, and true otherwise. The parentGroupIdEquals variable never gets modified after this, nor does the parentGroupId variable, which is passed in as an argument, ever get modified.

      Later on in the method, when filtering out groups by their parent group, we have the following code:

      long groupParentGroupId = group.getParentGroupId();
      
      if ((parentGroupIdEquals &&
      	 (groupParentGroupId != parentGroupId)) ||
      	(!parentGroupIdEquals &&
      	 (groupParentGroupId == parentGroupId))) {
      
      	iterator.remove();
      
      	continue;
      }
      

      However, the second half of that OR statement is pointless. If parentGroupIdEquals is false, then we know from the bolded statement above that parentGroupId is -1. However, no group will ever have their parentGroupId set to -1. Therefore, the following condition will never be true:

      (!parentGroupIdEquals &&
       (groupParentGroupId == parentGroupId)
      

      Therefore, it should be removed from the source code to improve readability.

        Attachments

          Activity

            People

            Assignee:
            brian.chan Brian Chan
            Reporter:
            michael.bowerman Michael Bowerman (Inactive)
            Participants of an Issue:
            Recent user:
            Csaba Turcsan
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Days since last comment:
              3 years, 22 weeks, 3 days ago

                Packages

                Version Package
                7.0.0 DXP FP23
                7.0.X EE
                7.0.4 CE GA5
                7.1.X
                Master