Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-2447

Null should not be returned from a "Boolean" method

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Null is returned but a "Boolean" is expected.
    • Default Severity:
      Critical
    • Impact:
      High
    • Likelihood:
      Low
    • Default Quality Profiles:
      Sonar way
    • Covered Languages:
      Java
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      20min
    • Analysis Scope:
      Main Sources, Test Sources
    • CERT:
      EXP01-J.
    • CWE:
      CWE-476
    • FindBugs:
      NP_BOOLEAN_RETURN_NULL

      Description

      While null is technically a valid Boolean value, that fact, and the distinction between Boolean and boolean is easy to forget. So returning null from a Boolean method is likely to cause problems with callers' code.

      Noncompliant Code Example

      public Boolean isUsable() {
        // ...
        return null;  // Noncompliant
      }
      

      See

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              ann.campbell.2 Ann Campbell
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: