Wiki Markup |
---|
A boxing conversion converts the value of a primitive type to the corresponding value of the reference type, for example, from {{int}} to {{Integer}} \[[JLS 2005|AA. Bibliography#JLS 05]\]. This is convenient in cases where an object parameter is required, such as with collection classes like {{Map}} and {{List}}. Another use case is for interoperation with methods that require their parameters to be object references rather than primitive types. Automatic conversion to the resulting wrapper types also reduces clutter in code. |
...
Allowing autoboxing to produce objects of an unintended type can cause silent failures with some APIs, such as the Collections
library. These failures can result in unintended object retention, memory leaks, or incorrect program operation.
Guideline Recommendation | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
EXP11EXP10-J | low | probable | low | P6 | L2 |
Automated Detection
Detection of invocations of Collection.remove()
whose operand fails to match the type of the elements of the underlying collection is straightforward. It is possible, albeit unlikely, that some of these invocations could be intended. The remainder are heuristically likely to be in error. Automated detection for other APIs may be possible.
...