<div dir="ltr">Hi all,<br><br>Internally at Google, we've had a Durations.MAX constant exposed for the past 7 years. It now has about 700 usages across our depot, which I can try to categorize (at a future date).<br><br>While I haven't performed that analysis yet, I think exposing this constant was a bit of a mistake. People seem to want to use MAX to mean "forever" (often in regards to an RPC deadline). This works fine as long as every single layer that touches the deadline is very careful about overflow. The only reasonable thing you can do with MAX is compareTo() and equals(). Attempting to do any simple math operation (e.g., now+deadline) is going to explode. Additionally, decomposing Duration.MAX explodes for any sub-second precision (e.g., toMillis()).<br><br>As we dug into this, another proposal came up which was something like Durations.VERY_LONG. This duration would be longer than any reasonable finite duration but not long enough to cause an overflow when added to any reasonable time. E.g., a million years would probably satisfy both criteria. This would mean math operations and decompositions won't explode (well, microseconds and nanoseconds still would), and it could safely be used as a relative timeout.<br><br>As I mentioned above, I'd be happy to try to categorize a sample of our 700 existing usages if folks think that would be useful for this proposal.<br><br>Thanks,<br><br>-Kurt Alfred Kluever (on behalf of Google's Java and Kotlin Ecosystem team)<br></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Wed, Sep 3, 2025 at 1:53 PM Pavel Rappo <<a href="mailto:pavel.rappo@gmail.com">pavel.rappo@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">If I understood you correctly, you think we should also add<br>
Duration.MIN. If so, what use case do you envision for it? Or we add<br>
if purely for symmetry with Instant?<br>
<br>
On Wed, Sep 3, 2025 at 6:43 PM Pavel Rappo <<a href="mailto:pavel.rappo@gmail.com" target="_blank">pavel.rappo@gmail.com</a>> wrote:<br>
><br>
> On Wed, Sep 3, 2025 at 6:06 PM Stephen Colebourne <<a href="mailto:scolebourne@joda.org" target="_blank">scolebourne@joda.org</a>> wrote:<br>
> ><br>
> > Hmm, yes. Not sure why that didn't get added in Java 8!<br>
> > The constants would be MAX/MIN as per classes like Instant.<br>
> > Stephen<br>
><br>
> I thought that naming could be tricky :) The public constant<br>
> Duration.ZERO and the public method isZero() are already there.<br>
> However, it does not preclude us from naming a new constant MAX.<br>
</blockquote></div><div><br clear="all"></div><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><font face="sans-serif"><span style="line-height:19px">kak</span></font></div>