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:53 UTC
[tomcat] branch 8.5.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 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push:
new 38b0faa8d7 Avoid potential ConcurrentModificationException by using Iterator.
38b0faa8d7 is described below
commit 38b0faa8d7e48b142db293483b72808fe817782a
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 4e34d70375..84badee774 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;
@@ -1295,9 +1296,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();
}
}
@@ -1310,17 +1313,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);
}
@@ -1394,12 +1400,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