A SimpleDateFormat or other java.text format is kept in a shared property, though it is not thread-safe
What it finds
SimpleDateFormat, DecimalFormat and MessageFormat keep state while they work, and their documentation says to give each thread its own instance. One kept in an object, a companion or at the top level is shared by all threads and gives wrong results under load. java.time.format.DateTimeFormatter is immutable and can be shared.
From the rule's source, shared_date_format.rs.
object Dates { val format = SimpleDateFormat("yyyy-MM-dd", Locale.ROOT)tx0 reports: the SimpleDateFormat in format is shared between threads} private val money = DecimalFormat("#.00")tx0 reports: the DecimalFormat in money is shared class Report { private val local = SimpleDateFormat("yyyy", Locale.ROOT)} 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:shared-date-format" = "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:shared-date-format] reason="..."tx0 explain tx0/kotlin:shared-date-format shows the same in the terminal. Found a false positive? Report it.