You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by li...@apache.org on 2022/09/09 14:58:22 UTC

[tomcat] branch 10.0.x updated: Avoid potential ConcurrentModificationException by using Iterator.

This is an automated email from the ASF dual-hosted git repository.

lihan pushed a commit to branch 10.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/10.0.x by this push:
     new d37106f04d Avoid potential ConcurrentModificationException by using Iterator.
d37106f04d is described below

commit d37106f04dbe6271b69f2ccc79cbdfeb8e6d659c
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 54c4d0df78..97619c7e25 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;
@@ -1293,9 +1294,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();
                 }
             }
 
@@ -1308,17 +1311,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);
                 }
@@ -1392,12 +1398,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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org