On Fri, 24 Oct 2025 12:10:38 GMT, Volkan Yazici <[email protected]> wrote:
> Introduce necessary fixes to address exceptions thrown when excessive
> `Duration`s are provided to `Duration`-accepting `HttpClient` public APIs.
src/java.net.http/share/classes/jdk/internal/net/http/common/Deadline.java line
73:
> 71: ArithmeticException _) { // "long overflow"
> 72: return nanosToAdd > 0 ? Deadline.MAX : Deadline.MIN;
> 73: }
We could add more fast-path checks here to take care of the special case where
this is already `Deadline.MAX` or `Deadline.MIN`, but we expect that in most
cases there will be no exception, so you have probably reached the sweet spot
by just checking for 0. This could be revisited later on when we have value
classes, and if Deadline and Instant are turned into value classes.
src/java.net.http/share/classes/jdk/internal/net/http/common/Deadline.java line
207:
> 205: ArithmeticException _) { // "long overflow"
> 206: return duration.isPositive() ? Deadline.MAX : Deadline.MIN;
> 207: }
This is the place where we could use the new method. As we probably will want
to backport I think it's better to keep the proposed implementation for now.
src/java.net.http/share/classes/jdk/internal/net/http/common/Deadline.java line
233:
> 231: public long until(Deadline endExclusive, TemporalUnit unit) {
> 232: int delta = compareTo(endExclusive);
> 233: if (delta == 0) return 0;
I'd suggest moving these two lines into the catch clause. We only need the
comparison when an exception is raised. I don't think the case where we would
get 0 occurs very often, and it would be handled correctly (without throwing)
by the regular path anyway.
src/java.net.http/share/classes/jdk/internal/net/http/common/Deadline.java line
321:
> 319: }
> 320: }
> 321:
Do we need to change this method? I would just revert them.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/27973#discussion_r2474834823
PR Review Comment: https://git.openjdk.org/jdk/pull/27973#discussion_r2474868867
PR Review Comment: https://git.openjdk.org/jdk/pull/27973#discussion_r2474899955
PR Review Comment: https://git.openjdk.org/jdk/pull/27973#discussion_r2475007515