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

Optional.orElse(getOther()) causes executes getOther() even if the Optional already has value

    Details

      Description

      java.util.Optional.orElse(T other) checks whether the value of the Optional is null; if not, return the value; if it is null, return the parameter. See:

      public T orElse(T other) {
          return value != null ? value : other;
      }
      

      So orElse(getOther()) is wrong, since getOther() will always be executed so that the return value can be passed to orElse().

        Attachments

          Activity

            People

            • Assignee:
              brian.chan Brian Chan
              Reporter:
              dante.wang Dante Wang
              Participants of an Issue:
              Recent user:
              Jason Pince
              Engineering Assignee:
              Dante Wang
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                20 weeks, 4 days ago

                Packages

                Version Package
                7.2.10 DXP FP1
                7.2.X
                7.2.1 CE GA2
                Master