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 13:03:53 UTC
svn commit: r979239 - in
/myfaces/core/branches/1.2.x/impl/src/main/java/org/apache/myfaces:
context/servlet/SessionMap.java util/AbstractAttributeMap.java
Author: jakobk
Date: Mon Jul 26 11:03:53 2010
New Revision: 979239
URL: http://svn.apache.org/viewvc?rev=979239&view=rev
Log:
MYFACES-2840 Use a copied Iterator instead of the real Enumeration in AbstractAttributeMap.AbstractAttributeIterator (fix for 1.2.x + minor cleanup in AbstractAttributeMap and in SessionMap)
Modified:
myfaces/core/branches/1.2.x/impl/src/main/java/org/apache/myfaces/context/servlet/SessionMap.java
myfaces/core/branches/1.2.x/impl/src/main/java/org/apache/myfaces/util/AbstractAttributeMap.java
Modified: myfaces/core/branches/1.2.x/impl/src/main/java/org/apache/myfaces/context/servlet/SessionMap.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1.2.x/impl/src/main/java/org/apache/myfaces/context/servlet/SessionMap.java?rev=979239&r1=979238&r2=979239&view=diff
==============================================================================
--- myfaces/core/branches/1.2.x/impl/src/main/java/org/apache/myfaces/context/servlet/SessionMap.java (original)
+++ myfaces/core/branches/1.2.x/impl/src/main/java/org/apache/myfaces/context/servlet/SessionMap.java Mon Jul 26 11:03:53 2010
@@ -46,7 +46,7 @@ public final class SessionMap extends Ab
@Override
protected Object getAttribute(final String key)
{
- final HttpSession httpSession = getSession();
+ final HttpSession httpSession = _getSession();
return (httpSession == null) ? null : httpSession.getAttribute(key);
}
@@ -59,7 +59,7 @@ public final class SessionMap extends Ab
@Override
protected void removeAttribute(final String key)
{
- final HttpSession httpSession = getSession();
+ final HttpSession httpSession = _getSession();
if (httpSession != null)
{
httpSession.removeAttribute(key);
@@ -70,34 +70,21 @@ public final class SessionMap extends Ab
@SuppressWarnings("unchecked")
protected Enumeration<String> getAttributeNames()
{
- final HttpSession httpSession = getSession();
+ final HttpSession httpSession = _getSession();
return (httpSession == null) ? NullEnumeration.instance() : httpSession.getAttributeNames();
}
- private HttpSession getSession()
- {
- return _httpRequest.getSession(false);
- }
-
@Override
public void putAll(final Map t)
{
throw new UnsupportedOperationException();
}
-
- /**
- * This will clear the session without invalidation. If no session has been created, it will simply return.
- */
- @Override
- public void clear()
+
+ // we can use public void clear() from super-class
+
+ private HttpSession _getSession()
{
- final HttpSession session = getSession();
- if (session == null)
- return;
- for (final Enumeration attributeNames = session.getAttributeNames(); attributeNames.hasMoreElements();)
- {
- final String attributeName = (String) attributeNames.nextElement();
- session.removeAttribute(attributeName);
- }
+ return _httpRequest.getSession(false);
}
-}
\ No newline at end of file
+
+}
Modified: myfaces/core/branches/1.2.x/impl/src/main/java/org/apache/myfaces/util/AbstractAttributeMap.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1.2.x/impl/src/main/java/org/apache/myfaces/util/AbstractAttributeMap.java?rev=979239&r1=979238&r2=979239&view=diff
==============================================================================
--- myfaces/core/branches/1.2.x/impl/src/main/java/org/apache/myfaces/util/AbstractAttributeMap.java (original)
+++ myfaces/core/branches/1.2.x/impl/src/main/java/org/apache/myfaces/util/AbstractAttributeMap.java Mon Jul 26 11:03:53 2010
@@ -22,6 +22,7 @@ import java.util.AbstractMap;
import java.util.AbstractSet;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
@@ -43,11 +44,7 @@ public abstract class AbstractAttributeM
public void clear()
{
- final List<String> names = new ArrayList<String>();
- for (final Enumeration<String> e = getAttributeNames(); e.hasMoreElements();)
- {
- names.add(e.nextElement());
- }
+ final List<String> names = Collections.list(getAttributeNames());
for (String name : names) {
removeAttribute(name);
@@ -193,14 +190,17 @@ public abstract class AbstractAttributeM
private abstract class AbstractAttributeIterator<E> implements Iterator<E>
{
- protected final Enumeration<String> _e = getAttributeNames();
+ // 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<String> _i = Collections.list(getAttributeNames()).iterator();
protected String _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("You must call next() at least once");
@@ -210,12 +210,12 @@ public abstract class AbstractAttributeM
public boolean hasNext()
{
- return _e.hasMoreElements();
+ return _i.hasNext();
}
public E next()
{
- return getValue(_currentKey = _e.nextElement());
+ return getValue(_currentKey = _i.next());
}
protected abstract E getValue(String attributeName);