CWE-1235 - Incorrect Use of Autoboxing and Unboxing for Performance Critical Operations
CWE-1235
- Abstraction:
- Base
- Structure:
- Simple
- Status:
- Incomplete
- Weakness Name
Incorrect Use of Autoboxing and Unboxing for Performance Critical Operations
- Description
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.
- Common Consequences
Scope: Availability
Impact: DoS: Resource Consumption (CPU), DoS: Resource Consumption (Memory), DoS: Resource Consumption (Other), Reduce Performance
Notes: Incorrect autoboxing/unboxing would result in reduced performance, which sometimes can lead to resource consumption issues.
- Related Weaknesses
- Release Date:
- 2020-02-24
- Latest Modification Date:
- 2023-06-29
Free security scan for your website