This is an automated email from the ASF dual-hosted git repository. lihan pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push: new d0b641313a Avoid potential ConcurrentModificationException by using Iterator. d0b641313a is described below commit d0b641313a5d52e621099e53899828357c8eff32 Author: lihan <li...@apache.org> AuthorDate: Fri Sep 9 22:57:17 2022 +0800 Avoid potential ConcurrentModificationException by using Iterator. --- .../apache/catalina/servlets/WebdavServlet.java | 36 +++++++++++++--------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/java/org/apache/catalina/servlets/WebdavServlet.java b/java/org/apache/catalina/servlets/WebdavServlet.java index 33ae4f9bd6..f0e5d9da51 100644 --- a/java/org/apache/catalina/servlets/WebdavServlet.java +++ b/java/org/apache/catalina/servlets/WebdavServlet.java @@ -30,6 +30,7 @@ import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.List; +import java.util.Iterator; import java.util.Locale; import java.util.Map; import java.util.Stack; @@ -1292,9 +1293,11 @@ public class WebdavServlet extends DefaultServlet { if (lock != null) { // At least one of the tokens of the locks must have been given - for (String token : lock.tokens) { + Iterator<String> tokenList = lock.tokens.iterator(); + while (tokenList.hasNext()) { + String token = tokenList.next(); if (lockTokenHeader.contains(token)) { - lock.tokens.remove(token); + tokenList.remove(); } } @@ -1307,17 +1310,20 @@ public class WebdavServlet extends DefaultServlet { } // Checking inheritable collection locks - for (LockInfo collectionLock : collectionLocks) { - if (path.equals(collectionLock.path)) { - for (String token : collectionLock.tokens) { + Iterator<LockInfo> collectionLocksList = collectionLocks.iterator(); + while (collectionLocksList.hasNext()) { + lock = collectionLocksList.next(); + if (path.equals(lock.path)) { + Iterator<String> tokenList = lock.tokens.iterator(); + while (tokenList.hasNext()) { + String token = tokenList.next(); if (lockTokenHeader.contains(token)) { - collectionLock.tokens.remove(token); + tokenList.remove(); break; } } - - if (collectionLock.tokens.isEmpty()) { - collectionLocks.remove(collectionLock); + if (lock.tokens.isEmpty()) { + collectionLocksList.remove(); // Removing any lock-null resource which would be present lockNullResources.remove(path); } @@ -1391,12 +1397,14 @@ public class WebdavServlet extends DefaultServlet { } // Checking inheritable collection locks - for (LockInfo collectionsLock : collectionLocks) { - if (collectionsLock.hasExpired()) { - collectionLocks.remove(collectionsLock); - } else if (path.startsWith(collectionsLock.path)) { + Iterator<LockInfo> collectionLockList = collectionLocks.iterator(); + while (collectionLockList.hasNext()) { + lock = collectionLockList.next(); + if (lock.hasExpired()) { + collectionLockList.remove(); + } else if (path.startsWith(lock.path)) { boolean tokenMatch = false; - for (String token : collectionsLock.tokens) { + for (String token : lock.tokens) { if (ifHeader.contains(token)) { tokenMatch = true; break; --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org