Uploaded image for project: 'mdsal'
  1. mdsal
  2. MDSAL-18

Return an empty list and never null from list-valued parameters in generated models

    XMLWordPrintable

Details

    • Improvement
    • Status: Resolved
    • Resolution: Done
    • None
    • 3.0.2
    • None
    • Operating System: Linux
      Platform: PC

    Description

      In our builders, we should never accept a null-valued list. When building the object, if the list-valued field is null, then we should set it to Collections.emptyList() instead. This makes writing code much more pleasant and really has no downside.

       

      We have something like this:
      // check if empty
      if (myObjects.getListParam() == null || myObjects.getListParam().size() == 0) {
          // ...
      }
      
      becomes:
      if (myObjects.getListParam().size() == 0) {
          // ...
      }
      
      And this:
      
      if (myObjects.getListParam() != null) {
          for (ListValue v : myObjects.getListParam()) {
              // ...
          }
      }
      
      becomes:
      for (ListValue v : myObjects.getListParam()) {
          // ...
      }
      

       

      Much nicer!

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              rovarga Robert Varga
              readams Rob Adams
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: