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

Void methods with no side effects should be removed

    XMLWordPrintable

    Details

    • Type: Bug Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Remove this useless method or refactor it to add the missing side effects.
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way, MISRA C++ 2008 recommended
    • Targeted languages:
      C#, C++, Flex, Java, Objective-C, Swift
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      30min
    • FindBugs:
      UC_USELESS_VOID_METHOD

      Description

      Methods with a void return type that neither alter their objects' state nor the states of their arguments are effectively useless. They should either be eliminated, or - more likely - corrected to include the missing side effects.

      Noncompliant Code Example

      public void whatsThePoint(List<Integer> ints) {  // Noncompliant
        int sum = 0;
        for (Integer i : ints) {
          sum += i.intValue();
        }
      }
      

        Attachments

          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: