tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jkemn...@apache.org
Subject [1/2] tapestry-5 git commit: TAP5-2526: detect more concurrent modifications
Date Mon, 11 Jan 2016 09:39:11 GMT
Repository: tapestry-5
Updated Branches:
  refs/heads/master 69d92296b -> e2a092b6c


TAP5-2526: detect more concurrent modifications


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/15a1dbf1
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/15a1dbf1
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/15a1dbf1

Branch: refs/heads/master
Commit: 15a1dbf1c66176abf167e12b0ffdab79342853df
Parents: 69d9229
Author: Jochen Kemnade <jochen.kemnade@eddyson.de>
Authored: Mon Jan 11 10:32:00 2016 +0100
Committer: Jochen Kemnade <jochen.kemnade@eddyson.de>
Committed: Mon Jan 11 10:32:00 2016 +0100

----------------------------------------------------------------------
 .../tapestry5/ioc/util/CaseInsensitiveMap.java  | 77 ++++++++++++--------
 1 file changed, 45 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/15a1dbf1/commons/src/main/java/org/apache/tapestry5/ioc/util/CaseInsensitiveMap.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/tapestry5/ioc/util/CaseInsensitiveMap.java b/commons/src/main/java/org/apache/tapestry5/ioc/util/CaseInsensitiveMap.java
index 4950c16..ab59d20 100644
--- a/commons/src/main/java/org/apache/tapestry5/ioc/util/CaseInsensitiveMap.java
+++ b/commons/src/main/java/org/apache/tapestry5/ioc/util/CaseInsensitiveMap.java
@@ -277,25 +277,31 @@ public class CaseInsensitiveMap<V> extends AbstractMap<String,
V> implements Ser
 
             int newSize = size + 1;
 
-            if (newSize == entries.length)
+            try
             {
-                // Time to expand!
+                if (newSize == entries.length)
+                {
+                    // Time to expand!
 
-                int newCapacity = (size * 3) / 2 + 1;
+                    int newCapacity = (size * 3) / 2 + 1;
 
-                CIMEntry<V>[] newEntries = new CIMEntry[newCapacity];
+                    CIMEntry<V>[] newEntries = new CIMEntry[newCapacity];
 
-                System.arraycopy(entries, 0, newEntries, 0, cursor);
+                    System.arraycopy(entries, 0, newEntries, 0, cursor);
 
-                System.arraycopy(entries, cursor, newEntries, cursor + 1, size - cursor);
+                    System.arraycopy(entries, cursor, newEntries, cursor + 1, size - cursor);
 
-                entries = newEntries;
-            }
-            else
+                    entries = newEntries;
+                }
+                else
+                {
+                    // Open up a space for the new entry
+                    System.arraycopy(entries, cursor, entries, cursor + 1, size - cursor);
+                }
+            } catch (ArrayIndexOutOfBoundsException e)
             {
-                // Open up a space for the new entry
-
-                System.arraycopy(entries, cursor, entries, cursor + 1, size - cursor);
+                // TAP5-2526
+                throw new ConcurrentModificationException();
             }
 
             CIMEntry<V> newEntry = new CIMEntry<V>(key, hashCode, newValue);
@@ -467,31 +473,38 @@ public class CaseInsensitiveMap<V> extends AbstractMap<String,
V> implements Ser
 
         int cursor;
 
-        while (low <= high)
+        try
         {
-            cursor = (low + high) >> 1;
-
-            CIMEntry<V> e = entries[cursor];
-
-            if (e == null)
+            while (low <= high)
             {
-                // TAP5-2520
-                throw new ConcurrentModificationException();
-            }
+                cursor = (low + high) >> 1;
 
-            if (e.hashCode < hashCode)
-            {
-                low = cursor + 1;
-                continue;
-            }
+                CIMEntry<V> e = entries[cursor];
 
-            if (e.hashCode > hashCode)
-            {
-                high = cursor - 1;
-                continue;
+                if (e == null)
+                {
+                    // TAP5-2520
+                    throw new ConcurrentModificationException();
+                }
+
+                if (e.hashCode < hashCode)
+                {
+                    low = cursor + 1;
+                    continue;
+                }
+
+                if (e.hashCode > hashCode)
+                {
+                    high = cursor - 1;
+                    continue;
+                }
+
+                return tunePosition(key, hashCode, cursor);
             }
-
-            return tunePosition(key, hashCode, cursor);
+        } catch (ArrayIndexOutOfBoundsException e)
+        {
+            // TAP5-2526
+            throw new ConcurrentModificationException();
         }
 
         return new Position(low, false);


Mime
View raw message