4994637: LTP: java.beans.java_util_Map_PersistenceDelegate: ConcurrentModificationException
authormalenkov
Wed, 09 Jul 2008 19:29:07 +0400
changeset 1281 b2928adc218e
parent 1280 f58fc9f575e3
child 1282 00a51b36c173
4994637: LTP: java.beans.java_util_Map_PersistenceDelegate: ConcurrentModificationException Reviewed-by: peterz, loneid
jdk/src/share/classes/java/beans/MetaData.java
jdk/test/java/beans/XMLEncoder/Test4994637.java
jdk/test/java/beans/XMLEncoder/java_util_HashMap.java
--- a/jdk/src/share/classes/java/beans/MetaData.java	Wed Jul 09 15:25:38 2008 +0400
+++ b/jdk/src/share/classes/java/beans/MetaData.java	Wed Jul 09 19:29:07 2008 +0400
@@ -650,7 +650,7 @@
         // Remove the new elements.
         // Do this first otherwise we undo the adding work.
         if (newMap != null) {
-            for ( Object newKey : newMap.keySet() ) {
+            for (Object newKey : newMap.keySet().toArray()) {
                // PENDING: This "key" is not in the right environment.
                 if (!oldMap.containsKey(newKey)) {
                     invokeStatement(oldInstance, "remove", new Object[]{newKey}, out);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/beans/XMLEncoder/Test4994637.java	Wed Jul 09 19:29:07 2008 +0400
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4994637
+ * @summary Tests custom map encoding
+ * @author Sergey Malenkov
+ */
+
+import java.util.HashMap;
+
+public final class Test4994637 extends AbstractTest<HashMap> {
+    public static void main(String[] args) {
+        new Test4994637().test(true);
+    }
+
+    @Override
+    protected CustomMap getObject() {
+        return new CustomMap();
+    }
+
+    @Override
+    protected CustomMap getAnotherObject() {
+        CustomMap map = new CustomMap();
+        map.clear();
+        map.put(null, "zero");
+        return map;
+    }
+
+    public static final class CustomMap extends HashMap<String, String> {
+        public CustomMap() {
+            put("1", "one");
+            put("2", "two");
+            put("3", "three");
+        }
+    }
+}
--- a/jdk/test/java/beans/XMLEncoder/java_util_HashMap.java	Wed Jul 09 15:25:38 2008 +0400
+++ b/jdk/test/java/beans/XMLEncoder/java_util_HashMap.java	Wed Jul 09 19:29:07 2008 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright 2006-2007 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 2006-2008 Sun Microsystems, Inc.  All Rights Reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 4631471 4921212
+ * @bug 4631471 4921212 4994637
  * @summary Tests HashMap encoding
  * @author Sergey Malenkov
  */
@@ -36,10 +36,17 @@
         new java_util_HashMap().test(true);
     }
 
+    @Override
     protected Map<String, String> getObject() {
-        return new HashMap<String, String>();
+        Map<String, String> map = new HashMap<String, String>();
+        map.put(null, null);
+        map.put("key", "value");
+        map.put("key-null", "null-value");
+        map.put("way", "remove");
+        return map;
     }
 
+    @Override
     protected Map<String, String> getAnotherObject() {
         Map<String, String> map = new HashMap<String, String>();
         map.put(null, "null-value");
@@ -48,6 +55,7 @@
         return map;
     }
 
+    @Override
     protected void validate(Map<String, String> before, Map<String, String> after) {
         super.validate(before, after);
         validate(before);
@@ -55,10 +63,18 @@
     }
 
     private static void validate(Map<String, String> map) {
-        if (!map.isEmpty()) {
+        switch (map.size()) {
+        case 3:
             validate(map, null, "null-value");
             validate(map, "key", "value");
             validate(map, "key-null", null);
+            break;
+        case 4:
+            validate(map, null, null);
+            validate(map, "key", "value");
+            validate(map, "key-null", "null-value");
+            validate(map, "way", "remove");
+            break;
         }
     }