toString on Array
ID |
kotlin.tostring_on_array |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Reliability |
Language |
Kotlin |
Tags |
array, reliability |
Description
Reports calls to toString() on an array type.
Arrays in Kotlin (and Java) inherit toString() from Object, which returns an address-like
string such as [I@1b6d3586 — the internal type descriptor followed by the identity hash code.
This string carries no information about the array’s elements and is almost never what was intended.
Rationale
val a = intArrayOf(1, 2, 3)
println(a.toString()) // FLAW — prints "[I@1b6d3586"
println(a.contentToString()) // OK — prints "[1, 2, 3]"