Difference between revisions of "Catch NullPointerException"

From OWASP
Jump to: navigation, search
m (Reverted edits by LidroNerbo (Talk) to last version by KirstenS)
 
(8 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Template:Stub}}
+
{{Template:Vulnerability}}
 +
{{Template:Fortify}}
  
[[Category:Vulnerability]]
+
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}'''
  
[[Category:Improper Error Handling]]
+
[[ASDR_TOC_Vulnerabilities|Vulnerabilities Table of Contents]]
  
[[Category:Error Handling]]
+
==Description==
 +
 
 +
It is generally a bad practice to catch NullPointerException.
 +
 
 +
Programmers typically catch NullPointerException under three circumstances:
 +
 
 +
# The program contains a null pointer dereference. Catching the resulting exception was easier than fixing the underlying problem.
 +
# The program explicitly throws a NullPointerException to signal an error condition.
 +
# 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==
 +
TBD
 +
 
 +
==Examples ==
 +
 
 +
The following code mistakenly catches a NullPointerException.
 +
 
 +
<pre>
 +
  try {
 +
mysteryMethod();
 +
  }
 +
  catch (NullPointerException npe) {
 +
  }
 +
</pre>
 +
 
 +
==Related [[Attacks]]==
 +
 
 +
* [[Attack 1]]
 +
* [[Attack 2]]
 +
 
 +
 
 +
==Related [[Vulnerabilities]]==
 +
 
 +
* [[Vulnerability 1]]
 +
* [[Vulnerabiltiy 2]]
 +
 
 +
 
 +
==Related [[Controls]]==
 +
 
 +
* [[:Category:Error Handling]]
 +
 
 +
 
 +
 
 +
==Related [[Technical Impacts]]==
 +
 
 +
* [[Technical Impact 1]]
 +
* [[Technical Impact 2]]
 +
 
 +
 
 +
==References==
 +
Note: A reference to related [http://cwe.mitre.org/ CWE] or [http://capec.mitre.org/ CAPEC] article should be added when exists. Eg:
 +
 
 +
* [http://cwe.mitre.org/data/definitions/79.html CWE 79].
 +
* http://www.link1.com
 +
* [http://www.link2.com Title for the link2]
 +
 
 +
 
 +
 
 +
__NOTOC__
 +
 
 +
 
 +
[[Category:OWASP ASDR Project]]
 +
[[Category:Error Handling Vulnerability]]
 +
[[Category:Vulnerability]]

Latest revision as of 14:58, 26 May 2009

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/26/2009

Vulnerabilities Table of Contents

Description

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

TBD

Examples

The following code mistakenly catches a NullPointerException.

	  try {
		mysteryMethod();
	  }
	  catch (NullPointerException npe) {
	  }

Related Attacks


Related Vulnerabilities


Related Controls


Related Technical Impacts


References

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