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

"void" methods should not end with "return"

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Remove this useless "return" statement.
    • Default Severity:
      Minor
    • Impact:
      Low
    • Likelihood:
      Low
    • Default Quality Profiles:
      Sonar way, MISRA C++ 2008 recommended
    • Targeted languages:
      C, C++, Flex, Java, Objective-C, Swift
    • Irrelevant for Languages:
      C#, VB.Net
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      1min
    • Implementation details:
    • PMD:
      UnnecessaryReturn

      Description

      There's no need to end a void method with a return statement. Since nothing is actually being returned, the return can be omitted; void will be returned implicitly.

      Noncompliant Code Example

      public void incrementCount() {
        this.count++;
        return;  // Noncompliant
      }
      

      Compliant Solution

      public void incrementCount() {
        this.count++;
      }
      

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated: