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

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

      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!

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

              Created:
              Updated:
              Resolved: