RFR: 8368528: HttpClient.Builder.connectTimeout should accept arbitrarily large values [v2]
Daniel Fuchs
dfuchs at openjdk.org
Thu Oct 30 10:45:42 UTC 2025
On Wed, 29 Oct 2025 20:53:22 GMT, Volkan Yazici <vyazici at openjdk.org> wrote:
>> Introduce necessary fixes to address exceptions thrown when excessive `Duration`s are provided to `Duration`-accepting `HttpClient` public APIs.
>
> Volkan Yazici has updated the pull request incrementally with one additional commit since the last revision:
>
> Move `delta == 0` in `until()` to the catch block
Changes requested by dfuchs (Reviewer).
src/java.net.http/share/classes/jdk/internal/net/http/common/Deadline.java line 318:
> 316: // Hence, we should never receive a numeric overflow while calculating the delta between two deadlines.
> 317: throw new IllegalStateException("Unexpected overflow", exception);
> 318: }
hmmm... `DateTimeException` and `ArithmeticException` are both `RuntimeException`. We know they won't be thrown here, so there's no point in trying to catch them to replace them with another exception, since that would essentially be dead code. Removing the `@throws` from the API doc is the right call though.
If you want you can add an `@apiNote` to say this method will never throw `DateTimeException` or `ArithmeticException` since duration between two deadlines will never overflow; but this is an internal API so the comment in the code below is probably enough.
Suggestion:
if (startInclusive.equals(endExclusive)) return Duration.ZERO;
// `Deadline` works with `Instant` under the hood.
// Delta between `Instant.MIN` and `Instant.MAX` fits in a `Duration`.
// Hence, we should never receive a numeric overflow while calculating the delta between two deadlines.
return Duration.between(startInclusive.deadline, endExclusive.deadline);
-------------
PR Review: https://git.openjdk.org/jdk/pull/27973#pullrequestreview-3398689313
PR Review Comment: https://git.openjdk.org/jdk/pull/27973#discussion_r2477461476
More information about the net-dev
mailing list