rickygrimes
rickygrimes

Reputation: 2716

Incorrect number of arguments for type RetryCallback

I am using Spring's retry library to retry a webservice call in case any error occurs if the service is down, or there is a network timeout. However, I keep getting the below error in my code - Incorrect number of arguments for type RetryCallback<T,E>; it cannot be parameterized with arguments <Object>. The method I am implementing the logic against returns void, so I basically can't have the retry call return anything. Please advise what mistake I have made here -

 RetryTemplate retryTemplate = createRetryTemplate(3, 1000);
    return retryTemplate.execute(new RetryCallback<Object>() {
        @Override
        public Object doWithRetry(RetryContext context) throws Exception {
            userUpdateService.updateUser(userName, userID);
        }
    });

Upvotes: 1

Views: 3538

Answers (3)

gknicker
gknicker

Reputation: 5568

The type RetryCallback accepts two generic parameters (a return type and a thrown exception type), but you are passing only one.

public interface RetryCallback<T, E extends Throwable> {
    T  doWithRetry(RetryContext context) throws E;
}

So you would want to instantiate it like this:

new RetryCallback<Object, Throwable>() { //...

Upvotes: 1

Dongqing
Dongqing

Reputation: 686

RetryCallback asks for two type parameter, a return type and an exception type.

RetryTemplate retryTemplate = createRetryTemplate(3, 1000);
    return retryTemplate.execute(new RetryCallback<Object,Exception>() {
       @Override
       public Object doWithRetry(RetryContext context) throws Exception {
           userUpdateService.updateUser(userName, userID);
       }
    });

Upvotes: 3

acanby
acanby

Reputation: 2993

The documentation for RetryCallback specifies 2 types, where you've only specified one.

The second type is what derivative of Throwable you will (possibly) throw, eg Exception, which you also need to specify:

RetryTemplate retryTemplate = createRetryTemplate(3, 1000);
return retryTemplate.execute(new RetryCallback<Object, Exception>() {
    @Override
    public Object doWithRetry(RetryContext context) throws Exception {
        userUpdateService.updateUser(userName, userID);
    }
});  

Upvotes: 1

Related Questions