This site is the archived OWASP Foundation Wiki and is no longer accepting Account Requests.
To view the new OWASP Foundation website, please visit https://owasp.org

Dead Code: Unused Method

From OWASP
Revision as of 18:06, 19 July 2006 by Weilin Zhong (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This is a Vulnerability. To view all vulnerabilities, please see the Vulnerability Category page.

This article includes content generously donated to OWASP by MicroFocus Logo.png

Abstract

This method is not reachable from any method outside the class.

Description

This method is never called or is only called from other dead code.

Examples

Example 1: In the following class, the method doWork() can never be called.

	public class Dead {
	  private void doWork() {
		System.out.println("doing work");
	  }
	  public static void main(String[] args) {
		System.out.println("running Dead");
	  }
	}
<pre>

'''Example 2:''' 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.

<pre>
	public class DoubleDead {
	  private void doTweedledee() {
		doTweedledumb();
	  }
	  private void doTweedledumb() {
		doTweedledee();
	  }
	  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.)

Related Threats

Related Attacks

Related Vulnerabilities

Related Countermeasures

Categories