google / google/error-prone

JavaDurationGetSecondsToToSeconds rule is misleading and possibly harmful

Open
#5,290 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
7.2k
Forks
820
Avg merge
5h 9m
Merged PRs (30d)
50

Description

### Expected Behavior
`toSeconds()` accounts for seconds *and* nanos, unlike `getSeconds()`. This is confirmed by AI Overview (screenshot below).

### Actual Behavior
`toSeconds()` is implemented by `return seconds;` all the way to JDK 25. Hence, `getSeconds()` and `toSeconds()` return identical result. The way the rule is phrased may lead the user to believe these results are different and cause errors when a "conversion" is attempted.

### Screenshot
Interestingly, this AI Overview seems to be using the `JavaDurationGetSecondsToToSeconds` rule text to generate the advice, thus possibly creating a circular hallucination.
Image

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.