On 09/09/2022 15:57, li...@apache.org wrote:
This is an automated email from the ASF dual-hosted git repository.
lihan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new 5c5adba7fd Avoid potential ConcurrentModificationException by using
Iterator.
5c5adba7fd is described below
commit 5c5adba7fdfc02ddaaf3a229efce89852bc305ae
Author: lihan <li...@apache.org>
AuthorDate: Fri Sep 9 22:57:17 2022 +0800
Avoid potential ConcurrentModificationException by using Iterator.
Thanks for catching these.
Mark
---
.../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-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org