Rule Definition
Finally blocks must be used to execute the code that is needed after either the try and/or the catch block have been executed. It is usually the place to code the release of resources used in the try block. As such, an empty finally block is most probably the sign of potential "resource leaks" that will jeopardize the application's stability.
Remediation
Avoid empty finally blocks. Finally block should contain code to release resource.
Violation Code Sample
>>> def experiment():
>>> try:
>>> x = 2/0
>>> except ZeroDivisionError as e:
>>> logging.debug("Division by 0 not possible")
>>> finally:
>>> pass
Fixed Code Sample
>>> def experiment():
>>> try:
>>> x = 2/0
>>> except ZeroDivisionError as e:
>>> logging.debug("Division by 0 not possible")
>>> finally:
>>> logging.debug("Quotient")
Reference
CISQ OMG ASCRM-RLB-01
Related Technologies
Technical Criterion
PCI-DSS4-Requirement-6.2.4 - Software engineering techniques or other methods are defined and in use by software development personnel to prevent or mitigate common software attacks and related vulnerabilities
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.