CS.METHOD.EMPTY

Avoid empty methods.

This rule identifies code that declares a method with an empty body. An error is reported for each occurrence.

NOTE: This rule does not apply for 'abstract', 'virtual', or 'override' methods to reserve the use of polymorphism.

Vulnerability and risk

During development empty methods often get introduced as place-holders for something to be implemented at a later time. Missing out implementation of important methods such as logging methods or methods that need to take important actions under abnormal cirucmstances, can be a risk to security.

Mitigation and prevention

To avoid oversights of this nature, it is best to ensure that there are no empty methods unless explicitly allowed (possibly via suppression of the violation).

Vulnerable code example

Copy
  namespace examples.rules.misc
  {
      public class EM
      {
          protected static void EmptyMethod(){} //VIOLATION
          public static void Main()
          {
              EmptyMethod();
              System.Console.WriteLine("EmptyMethods is called.");
         }
     }
 }

Deleting line 5 will resolve the issue.