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

ID CWE-1235
Abstraction Base
Structure Simple
Status Incomplete
The code uses boxed primitives, which may introduce inefficiencies into performance-critical operations.

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.

However, this feature comes at a cost of performance and can lead to resource exhaustion and impact availability when used with generic collections. Therefore, 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.

Modes of Introduction

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

Applicable Platforms

Type Class Name Prevalence
Language Java
Language C#
Operating_system Not OS-Specific
Architecture Not Architecture-Specific
Technology Not Technology-Specific

Relationships

View Weakness
# ID View Status # ID Name Abstraction Structure Status
CWE-1000 Research Concepts Draft CWE-400 Uncontrolled Resource Consumption Class Simple Draft
Loading...
Loading...