You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ja...@apache.org on 2010/07/26 12:51:26 UTC
svn commit: r979235 -
/myfaces/core/branches/1.1.x/impl/src/main/java/org/apache/myfaces/context/servlet/AbstractAttributeMap.java
Author: jakobk
Date: Mon Jul 26 10:51:26 2010
New Revision: 979235
URL: http://svn.apache.org/viewvc?rev=979235&view=rev
Log:
MYFACES-2840 Use a copied Iterator instead of the real Enumeration in AbstractAttributeMap.AbstractAttributeIterator (fix for 1.1.x + minor cleanup in AbstractAttributeMap)
Modified:
myfaces/core/branches/1.1.x/impl/src/main/java/org/apache/myfaces/context/servlet/AbstractAttributeMap.java
Modified: myfaces/core/branches/1.1.x/impl/src/main/java/org/apache/myfaces/context/servlet/AbstractAttributeMap.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1.1.x/impl/src/main/java/org/apache/myfaces/context/servlet/AbstractAttributeMap.java?rev=979235&r1=979234&r2=979235&view=diff
==============================================================================
--- myfaces/core/branches/1.1.x/impl/src/main/java/org/apache/myfaces/context/servlet/AbstractAttributeMap.java (original)
+++ myfaces/core/branches/1.1.x/impl/src/main/java/org/apache/myfaces/context/servlet/AbstractAttributeMap.java Mon Jul 26 10:51:26 2010
@@ -45,11 +45,7 @@ public abstract class AbstractAttributeM
public void clear()
{
- List names = new ArrayList();
- for (Enumeration e = getAttributeNames(); e.hasMoreElements();)
- {
- names.add(e.nextElement());
- }
+ final List names = _list(getAttributeNames());
for (Iterator it = names.iterator(); it.hasNext();)
{
@@ -141,7 +137,19 @@ public abstract class AbstractAttributeM
{
return (_values != null) ? _values : (_values = new Values());
}
-
+
+ /**
+ * Collections.list() from JDK 1.4
+ */
+ private ArrayList _list(Enumeration e) {
+ ArrayList l = new ArrayList();
+ while (e.hasMoreElements())
+ {
+ l.add(e.nextElement());
+ }
+ return l;
+ }
+
abstract protected Object getAttribute(String key);
@@ -188,14 +196,17 @@ public abstract class AbstractAttributeM
private class KeyIterator
implements Iterator
{
- protected final Enumeration _e = getAttributeNames();
- protected Object _currentKey;
+ // We use a copied version of the Enumeration from getAttributeNames()
+ // here, because directly using it might cause a ConcurrentModificationException
+ // when performing remove(). Note that we can do this since the Enumeration
+ // from getAttributeNames() will contain exactly the attribute names from the time
+ // getAttributeNames() was called and it will not be updated if attributes are
+ // removed or added.
+ protected final Iterator _i = _list(getAttributeNames()).iterator();
+ protected Object _currentKey;
public void remove()
{
- // remove() may cause ConcurrentModificationException.
- // We could throw an exception here, but not throwing an exception
- // allows one call to remove() to succeed
if (_currentKey == null)
{
throw new NoSuchElementException(
@@ -206,12 +217,12 @@ public abstract class AbstractAttributeM
public boolean hasNext()
{
- return _e.hasMoreElements();
+ return _i.hasNext();
}
public Object next()
{
- return _currentKey = _e.nextElement();
+ return _currentKey = _i.next();
}
}