---
title: "CWE-1071: Empty Code Block"
url: https://radicalnotion.ai/cwe/cwe-1071
type: cwe
description: "The source code contains a block that does not contain any code, i.e., the block is empty."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-1071: Empty Code Block

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

## Description

The source code contains a block that does not contain any code, i.e., the block is empty.

## Background

Empty code blocks can occur in the bodies of conditionals, function or method definitions, exception handlers, etc.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | For some programming languages and constructs, an empty block might be allowed by the syntax. While an empty code block might be intentional, it could accidentally occur when the developer did not finish implementation, accidental code deletion, unexpected macro expansion, etc. |

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Other | Reduce Reliability, Varies by Context | The lack of any behavior within the block might violate a convention or API in such a way that it is an error. It could indicate a situation in which some kind of action should be taken. |

## Detection methods

### Automated Static Analysis

Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

Effectiveness: High

## Demonstrative examples

### Example 1

In the following Java example, the code catches an ArithmeticException.

Bad code:

```java
public class Main {
    public static void main(String[] args) {
        int a = 1;
        int b = 0;
        int c = 0;

        try {
            c = a / b;

        } catch(ArithmeticException ae) {
        }

    }

}
```

Good code:

```java
public class Main {
    public static void main(String[] args) {
        int a = 1;
        int b = 0;
        int c = 0;

        try {
            c = a / b;

        } catch(ArithmeticException ae) {
            log.error("Divided by zero detected, setting to -1.");
            c = -1;

        }

    }

}
```

### Example 2

The following code attempts to synchronize on an object, but does not execute anything in the synchronized block. This does not actually accomplish anything and may be a sign that a programmer is wrestling with synchronization but has not yet achieved the result they intend.

Bad code:

```java
synchronized(this) { }
```

Good code:

```java
public void setID(int ID){
    synchronized(this){
        this.ID = ID;
    }
}
```

Instead, in a correct usage, the synchronized statement should contain procedures that access or modify data that is exposed to multiple threads. For example, consider a scenario in which several threads are accessing student records at the same time. The method which sets the student ID to a new value will need to make sure that nobody else is accessing this data at the same time and will require synchronization.

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-1164](https://radicalnotion.ai/cwe/cwe-1164) | Irrelevant Code |
| Child | [CWE-585](https://radicalnotion.ai/cwe/cwe-585) | Empty Synchronized Block |
| Child | [CWE-1069](https://radicalnotion.ai/cwe/cwe-1069) | Empty Exception Block |

## Frequently asked questions

### What is CWE-1071?

The source code contains a block that does not contain any code, i.e., the block is empty.

### How is CWE-1071 detected?

Automated Static Analysis: Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

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

Exploiting CWE-1071 can lead to: Reduce Reliability, Varies by Context.

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

---

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