mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 08:24:13 +00:00
Short-circuit matching algorithm in InstanceFilter
In commit 97522cfa36, I implemented a
short-circuiting matching algorithm in DefaultRetryPolicy for includes
and excludes, which was later copied to MethodRetrySpec.
After we switched to using ExceptionTypeFilter, I realized that the
matching algorithm in InstanceFilter (the superclass of
ExceptionTypeFilter) does not exhibit the same short-circuiting
characteristics.
In light of that, this commit revises the matching algorithm in
InstanceFilter to mirror the original short-circuiting algorithm in
DefaultRetryPolicy.
See gh-35058
See gh-35109
See gh-35160
Closes gh-35161
This commit is contained in:
@@ -86,21 +86,16 @@ public class InstanceFilter<T> {
|
||||
public boolean match(T instance) {
|
||||
Assert.notNull(instance, "Instance to match must not be null");
|
||||
|
||||
boolean includesSet = !this.includes.isEmpty();
|
||||
boolean excludesSet = !this.excludes.isEmpty();
|
||||
if (!includesSet && !excludesSet) {
|
||||
boolean emptyIncludes = this.includes.isEmpty();
|
||||
boolean emptyExcludes = this.excludes.isEmpty();
|
||||
|
||||
if (emptyIncludes && emptyExcludes) {
|
||||
return this.matchIfEmpty;
|
||||
}
|
||||
|
||||
boolean matchIncludes = match(instance, this.includes);
|
||||
boolean matchExcludes = match(instance, this.excludes);
|
||||
if (!includesSet) {
|
||||
return !matchExcludes;
|
||||
if (!emptyExcludes && match(instance, this.excludes)) {
|
||||
return false;
|
||||
}
|
||||
if (!excludesSet) {
|
||||
return matchIncludes;
|
||||
}
|
||||
return matchIncludes && !matchExcludes;
|
||||
return (emptyIncludes || match(instance, this.includes));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user