Skip to content

Commit 0d13e31

Browse files
SeasonPanPansnicoll
authored andcommitted
Use removeIf rather than Iterator-based removal
See gh-34762
1 parent 5a6e7d1 commit 0d13e31

File tree

2 files changed

+2
-14
lines changed
  • spring-boot-project

2 files changed

+2
-14
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/invoker/cache/CachingOperationInvoker.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,7 @@ private CacheKey getCacheKey(InvocationContext context) {
109109

110110
private void cleanExpiredCachedResponses(long accessTime) {
111111
try {
112-
Iterator<Entry<CacheKey, CachedResponse>> iterator = this.cachedResponses.entrySet().iterator();
113-
while (iterator.hasNext()) {
114-
Entry<CacheKey, CachedResponse> entry = iterator.next();
115-
if (entry.getValue().isStale(accessTime, this.timeToLive)) {
116-
iterator.remove();
117-
}
118-
}
112+
this.cachedResponses.entrySet().removeIf(entry -> entry.getValue().isStale(accessTime, this.timeToLive));
119113
}
120114
catch (Exception ex) {
121115
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnBeanCondition.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,7 @@ protected final MatchResult getMatchingBeans(ConditionContext context, Spec<?> s
182182
for (String type : spec.getTypes()) {
183183
Collection<String> typeMatches = getBeanNamesForType(classLoader, considerHierarchy, beanFactory, type,
184184
parameterizedContainers);
185-
Iterator<String> iterator = typeMatches.iterator();
186-
while (iterator.hasNext()) {
187-
String match = iterator.next();
188-
if (beansIgnoredByType.contains(match) || ScopedProxyUtils.isScopedTarget(match)) {
189-
iterator.remove();
190-
}
191-
}
185+
typeMatches.removeIf(match -> beansIgnoredByType.contains(match) || ScopedProxyUtils.isScopedTarget(match));
192186
if (typeMatches.isEmpty()) {
193187
result.recordUnmatchedType(type);
194188
}

0 commit comments

Comments
 (0)