CWE-395: Use of NullPointerException Catch to Detect NULL Pointer Dereference
|
Weakness ID: 395
Vulnerability Mapping:
ALLOWED
This CWE ID may be used to map to real-world vulnerabilities
Abstraction:
Variant
Variant - a weakness that is linked to a certain type of product, typically involving a specific language or technology. More specific than a Base weakness. Variant level weaknesses typically describe issues in terms of 3 to 5 of the following dimensions: behavior, property, technology, language, and resource.
|
View customized information:
Shows the description and diagram, platforms, mitigations, consequences, relationships, memberships, and content history.
For users who are interested in more notional aspects of a weakness. Example: educators, technical writers, and project/program managers.
For users who are concerned with the practical application and details about the nature of a weakness and how to prevent it from happening. Example: tool developers, security researchers, pen-testers, incident response analysts.
For users who are mapping an issue to CWE/CAPEC IDs, i.e., finding the most appropriate CWE for a specific issue (e.g., a CVE record). Example: tool developers, security researchers.
For users who wish to see all available information for the CWE/CAPEC entry.
For users who want to customize what details are displayed.
More information is available — Please edit the custom filter or select a different filter.
Description
Catching NullPointerException should not be used as an alternative to programmatic checks to prevent dereferencing a null pointer.
Common Consequences
This table specifies different individual consequences
associated with the weakness. The Scope identifies the application security area that is
violated, while the Impact describes the negative technical impact that arises if an
adversary succeeds in exploiting this weakness. The Likelihood provides information about
how likely the specific consequence is expected to be seen relative to the other
consequences in the list. For example, there may be high likelihood that a weakness will be
exploited to achieve a certain impact, but a low likelihood that it will be exploited to
achieve a different impact.
| Impact |
Details |
|
DoS: Resource Consumption (CPU)
|
Scope: Availability
|
|
Quality Degradation
|
Scope: Other
|
Potential Mitigations
| Phase(s) |
Mitigation |
|
Architecture and Design; Implementation
|
Do not extensively rely on catching exceptions (especially for validating user input) to handle errors. Handling exceptions can decrease the performance of an application.
|
Relationships
This table shows the weaknesses and high level categories that are related to this
weakness. These relationships are defined as ChildOf, ParentOf, MemberOf and give insight to
similar items that may exist at higher and lower levels of abstraction. In addition,
relationships such as PeerOf, Overlaps, and CanAlsoBe are defined to show similar weaknesses that the user
may want to explore.
|
Relevant to the view "Complete Weakness Hierarchy" (View-1000)
|
|
Nature |
Type |
ID |
Name |
|
ChildOf |
Class - a weakness that is described in a very abstract fashion, typically independent of any specific language or technology. More specific than a Pillar Weakness, but more general than a Base Weakness. Class level weaknesses typically describe issues in terms of 1 or 2 of the following dimensions: behavior, property, and resource.
|
705
|
Incorrect Control Flow Scoping
|
|
ChildOf |
Class - a weakness that is described in a very abstract fashion, typically independent of any specific language or technology. More specific than a Pillar Weakness, but more general than a Base Weakness. Class level weaknesses typically describe issues in terms of 1 or 2 of the following dimensions: behavior, property, and resource.
|
755
|
Improper Handling of Exceptional Conditions
|
|
|
Relevant to the view "Software Development" (View-699)
|
|
Nature |
Type |
ID |
Name |
|
MemberOf |
Grouping - a CWE entry that contains a set of other entries that share a common characteristic.
|
389
|
Error Conditions, Return Values, Status Codes
|
|
Modes
Of Introduction
The different Modes of Introduction provide information
about how and when this
weakness may be introduced. The Phase identifies a point in the life cycle at which
introduction
may occur, while the Note provides a typical scenario related to introduction during the
given
phase.
| Phase(s) |
Note |
|
Implementation
|
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.
|
Applicable Platforms
This listing shows possible areas for which the given
weakness could appear. These
may be for specific named Languages, Operating Systems, Architectures, Paradigms,
Technologies,
or a class of such platforms. The platform is listed along with how frequently the given
weakness appears for that instance.
| Type |
Applicable Platforms |
Notes |
| Languages |
Java
(Undetermined Prevalence)
|
|
Demonstrative Examples
Example 1
The following code mistakenly catches a NullPointerException.
(bad code)
Example Language: Java
try {
mysteryMethod();
} catch (NullPointerException npe) {
}
Weakness Ordinalities
| Ordinality |
Description |
|
Primary
|
(where the weakness exists independent of other weaknesses)
|
Detection
Methods
| Method |
Details |
|
Automated Static Analysis - Binary or Bytecode
|
According to SOAR [REF-1479], the following detection techniques may be useful:
Cost effective for partial coverage:
- Bytecode Weakness Analysis - including disassembler + source code weakness analysis
- Binary Weakness Analysis - including disassembler + source code weakness analysis
Effectiveness: SOAR Partial
|
|
Dynamic Analysis with Manual Results Interpretation
|
According to SOAR [REF-1479], the following detection techniques may be useful:
Cost effective for partial coverage:
Effectiveness: SOAR Partial
|
|
Manual Static Analysis - Source Code
|
According to SOAR [REF-1479], the following detection techniques may be useful:
Cost effective for partial coverage:
- Manual Source Code Review (not inspections)
Effectiveness: SOAR Partial
|
|
Automated Static Analysis - Source Code
|
According to SOAR [REF-1479], the following detection techniques may be useful:
Highly cost effective:
- Source code Weakness Analyzer
- Context-configured Source Code Weakness Analyzer
Effectiveness: High
|
|
Architecture or Design Review
|
According to SOAR [REF-1479], the following detection techniques may be useful:
Highly cost effective:
- Formal Methods / Correct-By-Construction
Cost effective for partial coverage:
- Inspection (IEEE 1028 standard) (can apply to requirements, design, source code, etc.)
Effectiveness: High
|
Vulnerability Mapping Notes
|
Usage
|
ALLOWED
(this CWE ID may be used to map to real-world vulnerabilities)
|
| Reason |
Acceptable-Use
|
|
Rationale
|
This CWE entry is at the Base level of abstraction, which is a preferred level of abstraction for mapping to the root causes of vulnerabilities.
|
|
Comments
|
Carefully read both the name and description to ensure that this mapping is an appropriate fit. Do not try to 'force' a mapping to a lower-level Base/Variant simply to comply with this preferred level of abstraction.
|
Taxonomy
Mappings
| Mapped Taxonomy Name |
Node ID |
Fit |
Mapped Node Name |
| 7 Pernicious Kingdoms |
|
|
Catching NullPointerException |
| The CERT Oracle Secure Coding Standard for Java (2011) |
ERR08-J |
|
Do not catch NullPointerException or any of its ancestors |
Content
History
| Submissions |
| Submission Date |
Submitter |
Organization |
2006-07-19
(CWE Draft 3, 2006-07-19)
|
7 Pernicious Kingdoms |
|
|
|
| Modifications |
| Modification Date |
Modifier |
Organization |
2026-10-28
(CWE 5.0, 2026-10-28)
|
CWE Content Team |
MITRE |
|
updated Common_Consequences, Description, Modes_of_Introduction, References, Type
|
2025-12-11
(CWE 4.19, 2025-12-11)
|
CWE Content Team |
MITRE |
|
updated Weakness_Ordinalities
|
2025-09-09
(CWE 4.18, 2025-09-09)
|
CWE Content Team |
MITRE |
|
updated Detection_Factors, References
|
2024-02-29
(CWE 4.14, 2024-02-29)
|
CWE Content Team |
MITRE |
|
updated Demonstrative_Examples
|
2023-06-29
(CWE 4.12, 2023-06-29)
|
CWE Content Team |
MITRE |
|
updated Mapping_Notes
|
2023-04-27
(CWE 4.11, 2023-04-27)
|
CWE Content Team |
MITRE |
|
updated Relationships
|
2020-02-24
(CWE 4.0, 2020-02-24)
|
CWE Content Team |
MITRE |
|
updated References
|
2019-01-03
(CWE 3.2, 2019-01-03)
|
CWE Content Team |
MITRE |
|
updated Taxonomy_Mappings
|
2014-07-30
(CWE 2.8, 2014-07-31)
|
CWE Content Team |
MITRE |
|
updated Detection_Factors, Relationships
|
2014-06-23
(CWE 2.7, 2014-06-23)
|
CWE Content Team |
MITRE |
|
updated Description, Other_Notes
|
2012-10-30
(CWE 2.3, 2012-10-30)
|
CWE Content Team |
MITRE |
|
updated Potential_Mitigations
|
2012-05-11
(CWE 2.2, 2012-05-15)
|
CWE Content Team |
MITRE |
|
updated Relationships
|
2011-06-01
(CWE 1.13, 2011-06-01)
|
CWE Content Team |
MITRE |
|
updated Common_Consequences, Relationships, Taxonomy_Mappings
|
2011-03-29
(CWE 1.12, 2011-03-30)
|
CWE Content Team |
MITRE |
|
updated Other_Notes, Relationships
|
2009-05-27
(CWE 1.4, 2009-05-27)
|
CWE Content Team |
MITRE |
|
updated Demonstrative_Examples
|
2009-03-10
(CWE 1.3, 2009-03-10)
|
CWE Content Team |
MITRE |
|
updated Relationships
|
2008-09-08
(CWE 1.0, 2008-09-09)
|
CWE Content Team |
MITRE |
|
updated Relationships, Other_Notes, Taxonomy_Mappings
|
2008-07-01
(CWE 1.0, 2008-09-09)
|
Eric Dalci |
Cigital |
|
updated Time_of_Introduction
|
| Previous Entry Names |
| Change Date |
Previous Entry Name |
| 2008-04-11
|
Catch NullPointerException |
More information is available — Please edit the custom filter or select a different filter.
|