Skip to content

Commit 21c74ce

Browse files
committed
Filter throwable by ExceptionTypeFilter.
Signed-off-by: Mengqi Xu <[email protected]>
1 parent e508dea commit 21c74ce

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

spring-core/src/main/java/org/springframework/core/retry/DefaultRetryPolicy.java

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@
2525
import org.jspecify.annotations.Nullable;
2626

2727
import org.springframework.util.Assert;
28+
import org.springframework.util.ExceptionTypeFilter;
2829

2930
/**
3031
* Default {@link RetryPolicy} created by {@link RetryPolicy.Builder}.
3132
*
3233
* @author Sam Brannen
3334
* @author Mahmoud Ben Hassine
35+
* @author Mengqi Xu
3436
* @since 7.0
3537
*/
3638
class DefaultRetryPolicy implements RetryPolicy {
@@ -105,6 +107,8 @@ private class DefaultRetryPolicyExecution implements RetryExecution {
105107

106108
private int retryCount;
107109

110+
private final ExceptionTypeFilter exceptionTypeFilter = new ExceptionTypeFilter(DefaultRetryPolicy.this.includes,
111+
DefaultRetryPolicy.this.excludes, true);
108112

109113
@Override
110114
public boolean shouldRetry(Throwable throwable) {
@@ -118,26 +122,8 @@ public boolean shouldRetry(Throwable throwable) {
118122
return false;
119123
}
120124
}
121-
if (!DefaultRetryPolicy.this.excludes.isEmpty()) {
122-
for (Class<? extends Throwable> excludedType : DefaultRetryPolicy.this.excludes) {
123-
if (excludedType.isInstance(throwable)) {
124-
return false;
125-
}
126-
}
127-
}
128-
if (!DefaultRetryPolicy.this.includes.isEmpty()) {
129-
boolean included = false;
130-
for (Class<? extends Throwable> includedType : DefaultRetryPolicy.this.includes) {
131-
if (includedType.isInstance(throwable)) {
132-
included = true;
133-
break;
134-
}
135-
}
136-
if (!included) {
137-
return false;
138-
}
139-
}
140-
return DefaultRetryPolicy.this.predicate == null || DefaultRetryPolicy.this.predicate.test(throwable);
125+
return this.exceptionTypeFilter.match(throwable.getClass()) &&
126+
(DefaultRetryPolicy.this.predicate == null || DefaultRetryPolicy.this.predicate.test(throwable));
141127
}
142128

143129
@Override

0 commit comments

Comments
 (0)