From 72b836f379209f23cad333ee8f9551f4a05e121e Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 1 Oct 2010 22:27:34 +0000 Subject: [PATCH] avoid ConcurrentModificationException when iterating attribute names (SPR-7557) git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3707 50f2f4bb-b051-0410-bef5-90022cba6387 --- .../springframework/mock/web/MockHttpServletRequest.java | 5 +++-- .../org/springframework/mock/web/MockHttpSession.java | 6 +++--- .../org/springframework/mock/web/MockPageContext.java | 6 +++--- .../org/springframework/mock/web/MockServletContext.java | 3 ++- .../mock/web/portlet/MockPortletContext.java | 7 ++++--- .../mock/web/portlet/MockPortletRequest.java | 5 +++-- .../mock/web/portlet/MockPortletSession.java | 9 +++++---- 7 files changed, 23 insertions(+), 18 deletions(-) diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/MockHttpServletRequest.java b/org.springframework.test/src/main/java/org/springframework/mock/web/MockHttpServletRequest.java index ca20451f66a..9f2cdbebab3 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/MockHttpServletRequest.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/MockHttpServletRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,6 +34,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; +import java.util.Vector; import javax.servlet.RequestDispatcher; import javax.servlet.ServletContext; import javax.servlet.ServletInputStream; @@ -284,7 +285,7 @@ public class MockHttpServletRequest implements HttpServletRequest { public Enumeration getAttributeNames() { checkActive(); - return Collections.enumeration(this.attributes.keySet()); + return new Vector(this.attributes.keySet()).elements(); } public String getCharacterEncoding() { diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/MockHttpSession.java b/org.springframework.test/src/main/java/org/springframework/mock/web/MockHttpSession.java index 757414dbbcc..e32f7fd5cd1 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/MockHttpSession.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/MockHttpSession.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,12 +17,12 @@ package org.springframework.mock.web; import java.io.Serializable; -import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Vector; import javax.servlet.ServletContext; import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSessionBindingEvent; @@ -137,7 +137,7 @@ public class MockHttpSession implements HttpSession { } public Enumeration getAttributeNames() { - return Collections.enumeration(this.attributes.keySet()); + return new Vector(this.attributes.keySet()).elements(); } public String[] getValueNames() { diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/MockPageContext.java b/org.springframework.test/src/main/java/org/springframework/mock/web/MockPageContext.java index 534500ac88f..fa8c16f1694 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/MockPageContext.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/MockPageContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,10 +17,10 @@ package org.springframework.mock.web; import java.io.IOException; -import java.util.Collections; import java.util.Enumeration; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Vector; import javax.el.ELContext; import javax.servlet.Servlet; import javax.servlet.ServletConfig; @@ -247,7 +247,7 @@ public class MockPageContext extends PageContext { } public Enumeration getAttributeNames() { - return Collections.enumeration(this.attributes.keySet()); + return new Vector(this.attributes.keySet()).elements(); } @SuppressWarnings("unchecked") diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/MockServletContext.java b/org.springframework.test/src/main/java/org/springframework/mock/web/MockServletContext.java index 55d04d71e60..59956a3d9be 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/MockServletContext.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/MockServletContext.java @@ -29,6 +29,7 @@ import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; +import java.util.Vector; import javax.activation.FileTypeMap; import javax.servlet.RequestDispatcher; import javax.servlet.Servlet; @@ -323,7 +324,7 @@ public class MockServletContext implements ServletContext { } public Enumeration getAttributeNames() { - return Collections.enumeration(this.attributes.keySet()); + return new Vector(this.attributes.keySet()).elements(); } public void setAttribute(String name, Object value) { diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletContext.java b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletContext.java index 4881300357d..45db454d8b2 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletContext.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,9 +28,10 @@ import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; +import java.util.Vector; +import javax.activation.FileTypeMap; import javax.portlet.PortletContext; import javax.portlet.PortletRequestDispatcher; -import javax.activation.FileTypeMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -209,7 +210,7 @@ public class MockPortletContext implements PortletContext { } public Enumeration getAttributeNames() { - return Collections.enumeration(this.attributes.keySet()); + return new Vector(this.attributes.keySet()).elements(); } public void setAttribute(String name, Object value) { diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletRequest.java b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletRequest.java index b885f358526..74419dcfbd2 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletRequest.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; +import java.util.Vector; import javax.portlet.PortalContext; import javax.portlet.PortletContext; import javax.portlet.PortletMode; @@ -327,7 +328,7 @@ public class MockPortletRequest implements PortletRequest { public Enumeration getAttributeNames() { checkActive(); - return Collections.enumeration(this.attributes.keySet()); + return new Vector(this.attributes.keySet()).elements(); } public void setParameters(Map parameters) { diff --git a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletSession.java b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletSession.java index 5c9ffb34542..d2c84be7ea0 100644 --- a/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletSession.java +++ b/org.springframework.test/src/main/java/org/springframework/mock/web/portlet/MockPortletSession.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.Map; +import java.util.Vector; import javax.portlet.PortletContext; import javax.portlet.PortletSession; import javax.servlet.http.HttpSessionBindingEvent; @@ -91,15 +92,15 @@ public class MockPortletSession implements PortletSession { } public Enumeration getAttributeNames() { - return Collections.enumeration(this.portletAttributes.keySet()); + return new Vector(this.portletAttributes.keySet()).elements(); } public Enumeration getAttributeNames(int scope) { if (scope == PortletSession.PORTLET_SCOPE) { - return Collections.enumeration(this.portletAttributes.keySet()); + return new Vector(this.portletAttributes.keySet()).elements(); } else if (scope == PortletSession.APPLICATION_SCOPE) { - return Collections.enumeration(this.applicationAttributes.keySet()); + return new Vector(this.applicationAttributes.keySet()).elements(); } return null; }