failsafe-lib / failsafe

Fault tolerance and resilience patterns for the JVM
https://failsafe.dev
Apache License 2.0
4.16k stars 295 forks source link

RetryPolicyConfig.getDelayMin returning null when only withDelay() is used #345

Closed MalikKillian closed 2 years ago

MalikKillian commented 2 years ago

Failsafe documentation describes the behavior of RetryPolicyConfig.getDelayMin as:

Returns the min delay between retries.

When the delay is set using the withDelay method the min delay is set to [and returns] null. The behavior is the same for the max delay.

Conventional thinking would imply that a fixed delay would result in the min and max delay becoming the same value.

A small code snippet to reproduce the behavior:

    RetryPolicy<Integer> policy = RetryPolicy.<Integer>builder()
      .withDelay(Duration.ofSeconds(1), Duration.ofSeconds(2)).build();
    policy.getConfig().getDelayMin().getSeconds();  // No issues
    policy.getConfig().getDelayMax().getSeconds();  // No issues
    policy.getConfig().getDelay().getSeconds();     // No issues (although this is zero)

    policy = RetryPolicy.<Integer>builder()
      .withDelay(Duration.ofSeconds(1)).build();
    policy.getConfig().getDelayMin()                // This is null
      .getSeconds();                                // NullPointerException

I think the docs should be updated to specify that min and max only exist if min and max are explicitly set OR (my preference) the use of withDelay should result in delayMax and delayMin being set to the same value.

jhalterman commented 2 years ago

Thanks for raising this. I pushed an improvement to the docs.