Uploaded image for project: 'OFBiz'
  1. OFBiz
  2. OFBIZ-7310

Use UtilValidate.isEmpty() instead of length() <= 0

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Trivial
    • Resolution: Done
    • Affects Version/s: Trunk
    • Fix Version/s: 16.11.01
    • Component/s: ALL COMPONENTS
    • Labels:
      None

      Description

      While reviewing Wai's patch for OFBIZ-7112 I noticed that he (re)used this pattern introduced earlier:

        (resource == null || resource.length() <= 0)
      

      From Java spec. a String, Collection, Map or CharSequence can't have a negative length, so the pattern above can be reduced to

        (resource == null || resource.length() == 0)
      

      which can be replaced using

        UtilValidate.isEmpty()
      

      I checked, there are several other occurrences of this pattern (some very old, I guess most were routinely copied from an initial occurrence). I decided to replace all of them.

      I did that already long ago for the

        (resource == null || resource.length() == 0)
      

      pattern. It remains 4 of them. Three are justified (because of the dependency on base component or because using isEmpty() on Object is disputable for performance reasons). I'll took care of the remaining one right away!

        Issue Links

          Activity

          Hide
          jacques.le.roux Jacques Le Roux added a comment -

          Done at revision: 1747976

          Show
          jacques.le.roux Jacques Le Roux added a comment - Done at revision: 1747976

            People

            • Assignee:
              jacques.le.roux Jacques Le Roux
              Reporter:
              jacques.le.roux Jacques Le Roux
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development