A date or time value is given a ChronoUnit it does not support, which throws
What it finds
Instant.now().plus(1, ChronoUnit.MONTHS) throws an UnsupportedTemporalTypeException: an Instant is a point on the time line without a calendar, so units that need one, from weeks up, do not apply to it. The java.time documentation lists the units each type takes: a Duration is made of seconds and nanoseconds, so get takes only those two and of and plus take no unit longer than a day; a LocalDate has no time of day and a LocalTime no date.
Reported is a ChronoUnit constant given to one of these methods, on a variable of the type or on the result of one of its factory methods, when the type does not support it.
From the rule's source, unsupported_temporal_unit.rs.
import java.time.Duration;import java.time.Instant;import java.time.LocalDate;import java.time.temporal.ChronoUnit; class Times { void shift(Instant start, Duration timeout, LocalDate day) { Instant a = start.plus(1, ChronoUnit.MONTHS);tx0 reports: an Instant does not support ChronoUnit.MONTHS Instant b = start.plus(1, ChronoUnit.DAYS); Instant c = Instant.now().truncatedTo(ChronoUnit.YEARS);tx0 reports: does not support ChronoUnit.YEARS long d = timeout.get(ChronoUnit.MILLIS);tx0 reports: Duration.get does not support ChronoUnit.MILLIS long e = timeout.get(ChronoUnit.SECONDS); Duration f = Duration.of(2, ChronoUnit.WEEKS);tx0 reports: Duration.of does not support LocalDate g = day.plus(3, ChronoUnit.HOURS);tx0 reports: a LocalDate does not support ChronoUnit.HOURS LocalDate h = day.plus(3, ChronoUnit.WEEKS); }} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/java:invalid-chrono-unit" = "off"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:invalid-chrono-unit] reason="..."tx0 explain tx0/java:invalid-chrono-unit shows the same in the terminal. Found a false positive? Report it.