RFR: 8339538: Wrong timeout computations in DnsClient [v5]

Daniel Fuchs dfuchs at openjdk.org
Tue Sep 10 14:47:10 UTC 2024


On Tue, 10 Sep 2024 09:38:35 GMT, Mark Sheppard <msheppar at openjdk.org> wrote:

>> Aleksei Efimov has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Measure time the caller spent waiting. Simplify timeoutLeft computation
>
> src/jdk.naming.dns/share/classes/com/sun/jndi/dns/DnsClient.java line 442:
> 
>> 440:                 // use 1L below to ensure conversion to long and avoid potential
>> 441:                 // integer overflow (timeout is an int).
>> 442:                 // no point in supporting timeout > Integer.MAX_VALUE, clamp if needed
> 
> if I have read this correctly,  timeout is of type int, thus int Math.clamp(int, int, int) is being called returning type int and promoting to long. Are there any side effects to consider here?  And as timeoutLeft (or remainingTimeout) and pktTimeout were both int and now is type long, then why have timeout declared as type  int ? 
> 
> consistency in various declared "timeout" variables' type ?

If I'm not mistaken here  it's `Math.clamp(long, long, long)` which is called - because `timeout * (1L << retry)` is a long. We could make it more obvious by using `0L` instead of `0` too.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/20892#discussion_r1752129677


More information about the core-libs-dev mailing list