Skip to content

Commit

Permalink
GH-137: Improve RetryTemplate.setThrowLastExceptionOnExhausted() Ja…
Browse files Browse the repository at this point in the history
…vaDocs

Fixes: #137

* Fix couple code smells for arrays in the `RetryTemplate`
  • Loading branch information
artembilan committed May 13, 2024
1 parent 26697ea commit f6977d7
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.springframework.retry.policy.MapRetryContextCache;
import org.springframework.retry.policy.RetryContextCache;
import org.springframework.retry.policy.SimpleRetryPolicy;
import org.springframework.util.Assert;

/**
* Template class that simplifies the execution of operations with retry semantics.
Expand Down Expand Up @@ -120,6 +121,10 @@ public static RetryTemplate defaultInstance() {
}

/**
* Whether to re-throw last exception or wrap into {@link ExhaustedRetryException}
* when all retry attempts are exhausted. Defaults to {@code false}; applied only in
* case of supplied state, e.g.
* {@link org.springframework.retry.interceptor.StatefulRetryOperationsInterceptor}.
* @param throwLastExceptionOnExhausted the throwLastExceptionOnExhausted to set
*/
public void setThrowLastExceptionOnExhausted(boolean throwLastExceptionOnExhausted) {
Expand All @@ -141,7 +146,8 @@ public void setRetryContextCache(RetryContextCache retryContextCache) {
* @see RetryListener
*/
public void setListeners(RetryListener[] listeners) {
this.listeners = Arrays.asList(listeners).toArray(new RetryListener[listeners.length]);
Assert.notNull(listeners, "'listeners' must not be null");
this.listeners = Arrays.copyOf(listeners, listeners.length);
}

/**
Expand All @@ -168,7 +174,7 @@ public void registerListener(RetryListener listener, int index) {
else {
list.add(index, listener);
}
this.listeners = list.toArray(new RetryListener[list.size()]);
this.listeners = list.toArray(new RetryListener[0]);
}

/**
Expand Down

0 comments on commit f6977d7

Please sign in to comment.