Skip to content

Commit 32b56a3

Browse files
committed
Short-circuit matching algorithm in InstanceFilter
In commit 97522cf, 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
1 parent 17df4b4 commit 32b56a3

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

spring-core/src/main/java/org/springframework/util/InstanceFilter.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,16 @@ public InstanceFilter(@Nullable Collection<? extends T> includes,
8686
public boolean match(T instance) {
8787
Assert.notNull(instance, "Instance to match must not be null");
8888

89-
boolean includesSet = !this.includes.isEmpty();
90-
boolean excludesSet = !this.excludes.isEmpty();
91-
if (!includesSet && !excludesSet) {
92-
return this.matchIfEmpty;
93-
}
89+
boolean emptyIncludes = this.includes.isEmpty();
90+
boolean emptyExcludes = this.excludes.isEmpty();
9491

95-
boolean matchIncludes = match(instance, this.includes);
96-
boolean matchExcludes = match(instance, this.excludes);
97-
if (!includesSet) {
98-
return !matchExcludes;
92+
if (emptyIncludes && emptyExcludes) {
93+
return this.matchIfEmpty;
9994
}
100-
if (!excludesSet) {
101-
return matchIncludes;
95+
if (!emptyExcludes && match(instance, this.excludes)) {
96+
return false;
10297
}
103-
return matchIncludes && !matchExcludes;
98+
return (emptyIncludes || match(instance, this.includes));
10499
}
105100

106101
/**

0 commit comments

Comments
 (0)