Dead Code

The product contains dead code, which can never be executed.


Dead code is code that can never be executed in a running program. The surrounding code makes it impossible for a section of code to ever be executed.


The following examples help to illustrate the nature of this weakness and describe methods or techniques which can be used to mitigate the risk.

Note that the examples here are by no means exhaustive and any given weakness may have many subtle varieties, each of which may require different detection methods or runtime controls.

Example One

The condition for the second if statement is impossible to satisfy. It requires that the variables be non-null, while on the only path where s can be assigned a non-null value there is a return statement.

String s = null;
if (b) {
  s = "Yes";

if (s != null) {

Example Two

In the following class, two private methods call each other, but since neither one is ever invoked from anywhere else, they are both dead code.

public class DoubleDead {
  private void doTweedledee() {
  private void doTweedledumb() {
  public static void main(String[] args) {
    System.out.println("running DoubleDead");

(In this case it is a good thing that the methods are dead: invoking either one would cause an infinite loop.)

Example Three

The field named glue is not used in the following class. The author of the class has accidentally put quotes around the field name, transforming it into a string constant.

public class Dead {

  String glue;

  public String getGlue() {
    return "glue";


See Also

Comprehensive Categorization: Poor Coding Practices

Weaknesses in this category are related to poor coding practices.

CISQ Quality Measures - Maintainability

Weaknesses in this category are related to the CISQ Quality Measures for Maintainability. Presence of these weaknesses could reduce the maintainability of the software.

SEI CERT Perl Coding Standard - Guidelines 50. Miscellaneous (MSC)

Weaknesses in this category are related to the rules and recommendations in the Miscellaneous (MSC) section of the SEI CERT Perl Coding Standard.

Comprehensive CWE Dictionary

This view (slice) covers all the elements in CWE.

Quality Weaknesses with Indirect Security Impacts

CWE identifiers in this view (slice) are quality issues that only indirectly make it easier to introduce a vulnerability and/or make the vulnerability more difficult t...

CWE Cross-section

This view contains a selection of weaknesses that represent the variety of weaknesses that are captured in CWE, at a level of abstraction that is likely to be useful t...

Common Weakness Enumeration content on this website is copyright of The MITRE Corporation unless otherwise specified. Use of the Common Weakness Enumeration and the associated references on this website are subject to the Terms of Use as specified by The MITRE Corporation.