Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throwable as first argument of explicit recover method should be optional #371

Merged
merged 1 commit into from
Jun 21, 2023

Conversation

quaff
Copy link
Contributor

@quaff quaff commented Jun 21, 2023

According to Javadoc of @recover, The Throwable first argument is optional. Before this commit,

java.lang.NullPointerException: Cannot invoke "java.lang.Class.isAssignableFrom(java.lang.Class)" because "meta.type" is null
	at org.springframework.retry.annotation.RecoverAnnotationRecoveryHandler.findClosestMatch(RecoverAnnotationRecoveryHandler.java:154)
	at org.springframework.retry.annotation.RecoverAnnotationRecoveryHandler.recover(RecoverAnnotationRecoveryHandler.java:75)
	at org.springframework.retry.interceptor.RetryOperationsInterceptor$ItemRecovererCallback.recover(RetryOperationsInterceptor.java:159)
	at org.springframework.retry.support.RetryTemplate.handleRetryExhausted(RetryTemplate.java:543)
	at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:389)
	at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:225)
	at org.springframework.retry.interceptor.RetryOperationsInterceptor.invoke(RetryOperationsInterceptor.java:124)
	at org.springframework.retry.annotation.AnnotationAwareRetryOperationsInterceptor.invoke(AnnotationAwareRetryOperationsInterceptor.java:160)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)

is raised for

@Retryable(retryFor = RuntimeException.class, recover = "recover")
public String service(String param) {
	throw new RuntimeException("Planned");
}

@Recover
public String recover(String param) {
	return param;
}

…onal

According to Javadoc of @recover, The Throwable first argument is optional.
Before this commit,
```
java.lang.NullPointerException: Cannot invoke "java.lang.Class.isAssignableFrom(java.lang.Class)" because "meta.type" is null
	at org.springframework.retry.annotation.RecoverAnnotationRecoveryHandler.findClosestMatch(RecoverAnnotationRecoveryHandler.java:154)
	at org.springframework.retry.annotation.RecoverAnnotationRecoveryHandler.recover(RecoverAnnotationRecoveryHandler.java:75)
	at org.springframework.retry.interceptor.RetryOperationsInterceptor$ItemRecovererCallback.recover(RetryOperationsInterceptor.java:159)
	at org.springframework.retry.support.RetryTemplate.handleRetryExhausted(RetryTemplate.java:543)
	at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:389)
	at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:225)
	at org.springframework.retry.interceptor.RetryOperationsInterceptor.invoke(RetryOperationsInterceptor.java:124)
	at org.springframework.retry.annotation.AnnotationAwareRetryOperationsInterceptor.invoke(AnnotationAwareRetryOperationsInterceptor.java:160)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)
```
is raised for
```java
@retryable(retryFor = RuntimeException.class, recover = "recover")
public String service(String param) {
	throw new RuntimeException("Planned");
}

@recover
public String recover(String param) {
	return param;
}
```
@artembilan artembilan added this to the 2.0.3 milestone Jun 21, 2023
@artembilan artembilan added the bug label Jun 21, 2023
Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@garyrussell ?

@garyrussell
Copy link
Contributor

Fine with me; it's a bit unusual to not expose the exception type to the recoverer, but there's no harm in this.

@artembilan artembilan merged commit dabb230 into spring-projects:main Jun 21, 2023
1 check passed
@artembilan
Copy link
Member

@quaff ,

Thank you very much for contribution; looking forward for more!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants