Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-9974

Add nullability annotations

    XMLWordPrintableJSON

Details

    Description

      the code in the "Content-Package to Feature Model Converter" should come with nullabillity annotations for method parameters and return values.

      take for example https://github.com/apache/sling-org-apache-sling-feature-cpconverter/blob/master/src/main/java/org/apache/sling/feature/cpconverter/accesscontrol/DefaultAclManager.java#L142-L165:

      • first checks for list of 'authorizations being null (line 147)
      • on line 160 calls 'addPath', which turn calls 'areEmpty' (i.e. checks for null or empty)
      • on line 164 calls 'addAclStatement', which in turn checks for null again and also calls 'areEmpty' (ie. checks for null or empty, see also SLING-9973)

      if my counting is correct:

      • 4 times testing if the given list is null
      • 2 times testing if the given list is empty

      where it could be just 1 single call to 'areEmpty' at the beginning of  the top method addStatements and return if that condition was met. i wouldn't be surprised if similar things could be found elsewhere in the module.

      IMHO consistently using notnull/nullable annotations and being conscious about it helps to prevent that kind of mistakes and makes the code more robust, easier to test and to read.

      Attachments

        Issue Links

          Activity

            People

              karlpauls Karl Pauls
              angela Angela Schreiber
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: