Skip to content

Commit aac2de9

Browse files
committed
avoid ConcurrentModificationException when iterating attribute names (SPR-7557)
1 parent cbab6fa commit aac2de9

File tree

7 files changed

+23
-18
lines changed

7 files changed

+23
-18
lines changed

org.springframework.test/src/main/java/org/springframework/mock/web/MockHttpServletRequest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,6 +34,7 @@
3434
import java.util.Locale;
3535
import java.util.Map;
3636
import java.util.Set;
37+
import java.util.Vector;
3738
import javax.servlet.RequestDispatcher;
3839
import javax.servlet.ServletContext;
3940
import javax.servlet.ServletInputStream;
@@ -284,7 +285,7 @@ public Object getAttribute(String name) {
284285

285286
public Enumeration<String> getAttributeNames() {
286287
checkActive();
287-
return Collections.enumeration(this.attributes.keySet());
288+
return new Vector<String>(this.attributes.keySet()).elements();
288289
}
289290

290291
public String getCharacterEncoding() {

org.springframework.test/src/main/java/org/springframework/mock/web/MockHttpSession.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,12 +17,12 @@
1717
package org.springframework.mock.web;
1818

1919
import java.io.Serializable;
20-
import java.util.Collections;
2120
import java.util.Enumeration;
2221
import java.util.HashMap;
2322
import java.util.Iterator;
2423
import java.util.LinkedHashMap;
2524
import java.util.Map;
25+
import java.util.Vector;
2626
import javax.servlet.ServletContext;
2727
import javax.servlet.http.HttpSession;
2828
import javax.servlet.http.HttpSessionBindingEvent;
@@ -137,7 +137,7 @@ public Object getValue(String name) {
137137
}
138138

139139
public Enumeration<String> getAttributeNames() {
140-
return Collections.enumeration(this.attributes.keySet());
140+
return new Vector<String>(this.attributes.keySet()).elements();
141141
}
142142

143143
public String[] getValueNames() {

org.springframework.test/src/main/java/org/springframework/mock/web/MockPageContext.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,10 +17,10 @@
1717
package org.springframework.mock.web;
1818

1919
import java.io.IOException;
20-
import java.util.Collections;
2120
import java.util.Enumeration;
2221
import java.util.LinkedHashMap;
2322
import java.util.Map;
23+
import java.util.Vector;
2424
import javax.el.ELContext;
2525
import javax.servlet.Servlet;
2626
import javax.servlet.ServletConfig;
@@ -247,7 +247,7 @@ else if (getAttribute(name, APPLICATION_SCOPE) != null) {
247247
}
248248

249249
public Enumeration<String> getAttributeNames() {
250-
return Collections.enumeration(this.attributes.keySet());
250+
return new Vector<String>(this.attributes.keySet()).elements();
251251
}
252252

253253
@SuppressWarnings("unchecked")

org.springframework.test/src/main/java/org/springframework/mock/web/MockServletContext.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.LinkedHashSet;
3030
import java.util.Map;
3131
import java.util.Set;
32+
import java.util.Vector;
3233
import javax.activation.FileTypeMap;
3334
import javax.servlet.RequestDispatcher;
3435
import javax.servlet.Servlet;
@@ -323,7 +324,7 @@ public Object getAttribute(String name) {
323324
}
324325

325326
public Enumeration<String> getAttributeNames() {
326-
return Collections.enumeration(this.attributes.keySet());
327+
return new Vector<String>(this.attributes.keySet()).elements();
327328
}
328329

329330
public void setAttribute(String name, Object value) {

org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletContext.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,9 +28,10 @@
2828
import java.util.LinkedHashSet;
2929
import java.util.Map;
3030
import java.util.Set;
31+
import java.util.Vector;
32+
import javax.activation.FileTypeMap;
3133
import javax.portlet.PortletContext;
3234
import javax.portlet.PortletRequestDispatcher;
33-
import javax.activation.FileTypeMap;
3435

3536
import org.apache.commons.logging.Log;
3637
import org.apache.commons.logging.LogFactory;
@@ -209,7 +210,7 @@ public Object getAttribute(String name) {
209210
}
210211

211212
public Enumeration<String> getAttributeNames() {
212-
return Collections.enumeration(this.attributes.keySet());
213+
return new Vector<String>(this.attributes.keySet()).elements();
213214
}
214215

215216
public void setAttribute(String name, Object value) {

org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletRequest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@
2626
import java.util.Locale;
2727
import java.util.Map;
2828
import java.util.Set;
29+
import java.util.Vector;
2930
import javax.portlet.PortalContext;
3031
import javax.portlet.PortletContext;
3132
import javax.portlet.PortletMode;
@@ -327,7 +328,7 @@ public Object getAttribute(String name) {
327328

328329
public Enumeration<String> getAttributeNames() {
329330
checkActive();
330-
return Collections.enumeration(this.attributes.keySet());
331+
return new Vector<String>(this.attributes.keySet()).elements();
331332
}
332333

333334
public void setParameters(Map<String, String[]> parameters) {

org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletSession.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
2121
import java.util.HashMap;
2222
import java.util.Iterator;
2323
import java.util.Map;
24+
import java.util.Vector;
2425
import javax.portlet.PortletContext;
2526
import javax.portlet.PortletSession;
2627
import javax.servlet.http.HttpSessionBindingEvent;
@@ -91,15 +92,15 @@ else if (scope == PortletSession.APPLICATION_SCOPE) {
9192
}
9293

9394
public Enumeration<String> getAttributeNames() {
94-
return Collections.enumeration(this.portletAttributes.keySet());
95+
return new Vector<String>(this.portletAttributes.keySet()).elements();
9596
}
9697

9798
public Enumeration<String> getAttributeNames(int scope) {
9899
if (scope == PortletSession.PORTLET_SCOPE) {
99-
return Collections.enumeration(this.portletAttributes.keySet());
100+
return new Vector<String>(this.portletAttributes.keySet()).elements();
100101
}
101102
else if (scope == PortletSession.APPLICATION_SCOPE) {
102-
return Collections.enumeration(this.applicationAttributes.keySet());
103+
return new Vector<String>(this.applicationAttributes.keySet()).elements();
103104
}
104105
return null;
105106
}

0 commit comments

Comments
 (0)