Uploaded image for project: 'SonarJava'
  1. SonarJava
  2. SONARJAVA-4000

S1168 (ReturnEmptyArrayNotNullCheck) should also cover Maps

    XMLWordPrintable

    Details

    • Type: False Negative
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 7.3
    • Component/s: Rules
    • Labels:

      Description

      The rule targets methods returning Collections, which actually returns null in their body.

      While java.util.Map are not collections, they could suffer from the same problem, and it would always be safer to return an empty Map rather than null.

      Map<Object, Object> foo() {
        return null; // Noncompliant
      }
      
      Map<Object, Object> bar() {
        return Collections.emptyMap(); // Compliant
      }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              michael.gumowski Michael Gumowski
              Reporter:
              michael.gumowski Michael Gumowski
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: