Catch NullPointerException

Revision as of 14:26, 22 May 2009 by Deleted user (Talk | contribs)

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 Fortify.JPG.

Last revision (mm/dd/yy): 05/22/2009

Vulnerabilities Table of Contents


It is generally a bad practice to catch NullPointerException.

Programmers typically catch NullPointerException under three circumstances:

  1. The program contains a null pointer dereference. Catching the resulting exception was easier than fixing the underlying problem.
  2. The program explicitly throws a NullPointerException to signal an error condition.
  3. The code is part of a test harness that supplies unexpected input to the classes under test.

Of these three circumstances, only the last is acceptable.

Risk Factors



The following code mistakenly catches a NullPointerException.

	  try {
	  catch (NullPointerException npe) {

Related Attacks

Related Vulnerabilities

Related Controls

Related Technical Impacts


Note: A reference to related CWE or CAPEC article should be added when exists. Eg: