---
title: "CWE-1235: Incorrect Use of Autoboxing and Unboxing for Performance Critical Operations"
url: https://radicalnotion.ai/cwe/cwe-1235
type: cwe
description: "The code uses boxed primitives, which may introduce inefficiencies into performance-critical operations."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-1235: Incorrect Use of Autoboxing and Unboxing for Performance Critical Operations

- **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 code uses boxed primitives, which may introduce inefficiencies into performance-critical operations.

## Background

Languages such as Java and C# support automatic conversion through their respective compilers from primitive types into objects of the corresponding wrapper classes, and vice versa. For example, a compiler might convert an int to Integer (called autoboxing) or an Integer to int (called unboxing). This eliminates forcing the programmer to perform these conversions manually, which makes the code cleaner.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | The programmer may use boxed primitives when not strictly necessary. |

## Applicable platforms

**Languages:** Java (Undetermined), C# (Undetermined)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Availability | DoS: Resource Consumption (CPU), DoS: Resource Consumption (Memory), DoS: Resource Consumption (Other), Reduce Performance | Incorrect autoboxing/unboxing would result in reduced performance, which sometimes can lead to resource consumption issues, impacting availability when used with generic collections. |

## Potential mitigations

### Implementation

Use of boxed primitives should be limited to certain situations such as when calling methods with typed parameters. They should not be used for scientific computing or other performance critical operations. They are only suited to support "impedance mismatch" between reference types and primitives. Examine the use of boxed primitives prior to use. Use SparseArrays or ArrayMap instead of HashMap to avoid performance overhead.

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

## Demonstrative examples

### Example 1

Java has a boxed primitive for each primitive type. A long can be represented with the boxed primitive Long. Issues arise where boxed primitives are used when not strictly necessary.

Bad code:

```java
Long count = 0L;
for (long i = 0; i < Integer.MAX_VALUE; i++) {
    count += i;
}
```

In the above loop, we see that the count variable is declared as a boxed primitive. This causes autoboxing on the line that increments. This causes execution to be magnitudes less performant (time and possibly space) than if the "long" primitive was used to declare the count variable, which can impact availability of a resource.

### Example 2

This code uses primitive long which fixes the issue.

Good code:

```java
long count = 0L;
for (long i = 0; i < Integer.MAX_VALUE; i++) {
    count += i;
}
```

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-400](https://radicalnotion.ai/cwe/cwe-400) | Uncontrolled Resource Consumption |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| SEI CERT Oracle Coding Standard for Java | Do not pass arguments to certain Java Collections Framework methods that are a different type than the collection parameter type | EXP04-J | - |
| ISA/IEC 62443 | Req SI-2 | Part 4-1 | - |

## Frequently asked questions

### What is CWE-1235?

The code uses boxed primitives, which may introduce inefficiencies into performance-critical operations.

### How do you prevent CWE-1235?

Use of boxed primitives should be limited to certain situations such as when calling methods with typed parameters. They should not be used for scientific computing or other performance critical operations. They are only suited to support "impedance mismatch" between reference types and primitives. Examine the use of boxed primitives prior to use. Use SparseArrays or ArrayMap instead of HashMap to avoid performance overhead.

### How is CWE-1235 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-1235?

Exploiting CWE-1235 can lead to: DoS: Resource Consumption (CPU), DoS: Resource Consumption (Memory), DoS: Resource Consumption (Other), Reduce Performance.

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

---

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