---
title: "CWE-395: Use of NullPointerException Catch to Detect NULL Pointer Dereference"
url: https://radicalnotion.ai/cwe/cwe-395
type: cwe
description: "Catching NullPointerException should not be used as an alternative to programmatic checks to prevent dereferencing a null pointer."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-395: Use of NullPointerException Catch to Detect NULL Pointer Dereference

- **Abstraction:** Variant
- **Structure:** Simple
- **Status:** Draft
- **CVEs with this as primary weakness:** 18
- **Of those, in CISA KEV:** 0
- **New in 2026:** 1
- **CWE catalog version:** 4.21

## Description

Catching NullPointerException should not be used as an alternative to programmatic checks to prevent dereferencing a null pointer.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | - |

## Applicable platforms

**Languages:** Java (Undetermined)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Availability | DoS: Resource Consumption (CPU) | - |
| Other | Quality Degradation | - |

## Potential mitigations

### 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.

## Detection methods

### 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:

- Framework-based Fuzzer

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:

Cost effective for partial coverage:

- Formal Methods / Correct-By-Construction
- Inspection (IEEE 1028 standard) (can apply to requirements, design, source code, etc.)

Effectiveness: High

## Demonstrative examples

### Example 1

The following code mistakenly catches a NullPointerException.

Bad code:

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

## Real CVEs with this weakness (sample of 12 of 18)

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2025-58142 | Mutiple vulnerabilities in the Viridian interface | critical | 9.8 | - | No | 2025-09-11 |
| CVE-2025-27466 | Mutiple vulnerabilities in the Viridian interface | critical | 9.8 | - | No | 2025-09-11 |
| CVE-2025-15514 | Ollama Multi-Modal Model Image Processing NULL Pointer Dereference | high | 8.7 | - | No | 2026-01-12 |
| CVE-2022-29508 | - | high | 7.8 | - | No | 2023-05-10 |
| CVE-2022-2832 | blender: Null pointer reference in blender thumbnail extractor | high | 7.5 | - | No | 2022-08-16 |
| CVE-2023-23904 | - | medium | 6.9 | - | No | 2024-09-16 |
| CVE-2013-2132 | Use of NullPointerException Catch to Detect NULL Pointer Dereference in Pymongo | medium | 6.9 | - | No | 2013-08-15 |
| CVE-2024-27659 | - | medium | 6.5 | - | No | 2024-02-29 |
| CVE-2024-27661 | - | medium | 6.5 | - | No | 2024-02-29 |
| CVE-2024-27658 | - | medium | 6.5 | - | No | 2024-02-29 |
| CVE-2024-27662 | - | medium | 6.5 | - | No | 2024-02-29 |
| CVE-2022-42879 | - | medium | 6.1 | - | No | 2023-11-14 |

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-705](https://radicalnotion.ai/cwe/cwe-705) | Incorrect Control Flow Scoping |
| Parent | [CWE-755](https://radicalnotion.ai/cwe/cwe-755) | Improper Handling of Exceptional Conditions |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| 7 Pernicious Kingdoms | Catching NullPointerException | - | - |
| The CERT Oracle Secure Coding Standard for Java (2011) | Do not catch NullPointerException or any of its ancestors | ERR08-J | - |

## Frequently asked questions

### What is CWE-395?

Catching NullPointerException should not be used as an alternative to programmatic checks to prevent dereferencing a null pointer.

### What CVEs are caused by CWE-395?

18 recorded CVEs are attributed to CWE-395, including CVE-2025-58142, CVE-2025-27466 and CVE-2025-15514.

### How do you prevent CWE-395?

Do not extensively rely on catching exceptions (especially for validating user input) to handle errors. Handling exceptions can decrease the performance of an application.

### How is CWE-395 detected?

Automated Static Analysis - Binary or Bytecode: According to SOAR, the following detection techniques may be useful:

### What are the consequences of CWE-395?

Exploiting CWE-395 can lead to: DoS: Resource Consumption (CPU), Quality Degradation.

### Is CWE-395 actively exploited?

18 recorded CVEs are caused by CWE-395; none are currently in CISA's KEV catalog of actively exploited flaws.

Primary source: [MITRE CWE](https://cwe.mitre.org/data/definitions/395.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/cwe/cwe-395). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
