
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
33 lines
750 B
Plaintext
33 lines
750 B
Plaintext
== Why is this an issue?
|
|
|
|
include::../description.adoc[]
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,kotlin]
|
|
----
|
|
val objs = mutableListOf<Any>()
|
|
objs.add("Hello")
|
|
|
|
objs.add(objs) // Noncompliant; StackOverflowException if objs.hashCode() called
|
|
objs.addAll(objs) // Noncompliant; behavior undefined
|
|
objs.containsAll(objs) // Noncompliant; always true
|
|
objs.removeAll(objs) // Noncompliant; confusing. Use clear() instead
|
|
objs.retainAll(objs) // Noncompliant; NOOP
|
|
----
|
|
|
|
=== Compliant solution
|
|
|
|
[source,kotlin]
|
|
----
|
|
val newList = mutableListOf<Any>()
|
|
val objs = mutableListOf<Any>()
|
|
objs.add("Hello")
|
|
|
|
objs.containsAll(newList) // Compliant
|
|
objs.addAll(newList) // Compliant
|
|
objs.removeAll(newList) // Compliant
|
|
objs.retainAll(newList) // Compliant
|
|
----
|
|
|