CodeTrainerMan opened a new issue, #1136:
URL: https://github.com/apache/flink-agents/issues/1136

   ### Problem
   
   `RetryExecutor` accepts negative values through its builder and only fails 
later, with an error that hides the actual misconfiguration.
   
   **1. Negative `maxRetries` produces a `NullPointerException`.**
   
   ```java
   RetryExecutor executor = RetryExecutor.builder().maxRetries(-1).build();
   executor.execute(() -> "never called", "op");
   ```
   
   `execute()` starts with `attempt = 0`, so `while (attempt <= maxRetries)` 
never enters the loop and `lastException` stays `null`. Execution then falls 
through to
   
   ```java
   throw new RuntimeException(
           String.format(
                   "Operation '%s' failed after %d retries: %s",
                   operationName, maxRetries, lastException.getMessage()),   // 
NPE here
           lastException);
   ```
   
   giving `java.lang.NullPointerException` with no mention of `maxRetries`, and 
the operation is silently never invoked.
   
   **2. Negative `initialBackoffMs` can surface as an unrelated JDK error.**
   
   With `initialBackoffMs(-5)`, `window` is negative, so `sleepTime = (long) 
(RANDOM.nextDouble() * (window + 1))` can be negative and `Thread.sleep` throws 
`IllegalArgumentException: timeout value is negative` — a message that says 
nothing about which parameter was wrong.
   
   Both are reachable from user-supplied configuration, since the builder is 
the documented way to configure retries.
   
   ### Proposed fix
   
   Validate in `Builder.build()` and fail fast with the parameter named:
   
   - `maxRetries < 0` -> `IllegalArgumentException`
   - `initialBackoffMs < 0` -> `IllegalArgumentException`
   - `maxBackoffMs < initialBackoffMs` -> `IllegalArgumentException`
   
   Legal values, including `maxRetries == 0`, keep their current behavior.
   
   ### Additional notes
   
   `RetryExecutorTest` currently has 10 cases but none for negative or zero 
parameters; the fix should come with a few boundary cases.
   
   I am happy to open a PR for this if a committer agrees with the approach.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to