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

Overrides should match their parent class methods in visibility

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      * Decrease the accessibility of this method to "xxx" to match the parent class implementation.
    • Highlighting:
      • visibility modifier
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Targeted languages:
      Swift
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      20min
    • CERT:
      MET04-J.
    • SwiftLint:
      no_extension_access_modifier

      Description

      When a method doesn't match it's super method in visibility (public, protected, ...), malicious callers could take advantage of the over-broad access offered by the child class to undermine the application.

      Noncompliant Code Example

      public class Parent {
      
        protected void foo() {
          //...
        }
      }
      
      public class Child extends Parent {
      
        public void foo() {  // Noncompliant
          // ...
          super.foo();
        }
      }
      

      Compliant Solution

      public class Parent {
      
        protected void foo() {
          //...
        }
      }
      
      public class Child extends Parent {
      
        protected void foo() {
          // ...
          super.foo();
        }
      }
      

      See

      • CERT, MET04-J. - Do not increase the accessibility of overridden or hidden methods

        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: