hashCode returns the same constant for every object, which puts all of them in one bucket of a hash table
What it finds
A constant hashCode keeps the contract but turns every HashMap and HashSet holding these objects into a list, with lookups in linear time.
From the rule's source, constant_hash_code.rs.
class Key(val id: Int) { override fun hashCode(): Int = 42tx0 reports: every object has the same hash code} class Other(val id: Int) { override fun hashCode(): Int = id} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/kotlin:constant-hash-code" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/kotlin:constant-hash-code] reason="..."tx0 explain tx0/kotlin:constant-hash-code shows the same in the terminal. Found a false positive? Report it.