!! is applied to a value that can never be null
What it finds
"text"!!, this!! or name!! for a val name: String asserts what the type already says. The assertion is noise, and it suggests to readers that the value could be null.
A value counts as never null when it is a literal, a string, a lambda, an object expression, a constructor call, or a val or parameter whose declared type, or literal initializer, admits no null. Type parameters are left out, since they may stand for a nullable type.
From the rule's source, redundant_not_null_assertion.rs.
class Greeter(private val prefix: String, private val suffix: String?) { fun greet(name: String, other: String?): String { val local = "x" val a = name!!tx0 reports: name can never be null val b = other!! val c = local!!tx0 reports: local can never be null val d = suffix!! val e = prefix!!tx0 reports: prefix can never be null val f = "text"!!tx0 reports: can never be null return a + b + c + d + e + f } fun <T> generic(value: T): T = value!!} 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:redundant-not-null-assertion" = "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:redundant-not-null-assertion] reason="..."tx0 explain tx0/kotlin:redundant-not-null-assertion shows the same in the terminal. Found a false positive? Report it.