Dates are handled with Date, Calendar or SimpleDateFormat instead of java.time

tx0/java:legacy-date-apistrictwarningsmell

What it finds

java.util.Date, Calendar and SimpleDateFormat are mutable, count months from 0, mix time zones into values that have none, and the formatter is not thread-safe. The java.time classes, added in Java 8, replace them.

Reported is the creation of a Date, GregorianCalendar or SimpleDateFormat and Calendar.getInstance().

From the rule's source, legacy_date_api.rs.

Example from the rule's tests
import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date; class Clock {  void now() {    Date a = new Date();tx0 reports: java.time classes replace this one    Calendar b = Calendar.getInstance();tx0 reports: replace this one    SimpleDateFormat c = new SimpleDateFormat("yyyy");tx0 reports: replace this one  }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/java:legacy-date-api" = "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/java:legacy-date-api] reason="..."

tx0 explain tx0/java:legacy-date-api shows the same in the terminal. Found a false positive? Report it.