diff --git a/jdk/src/share/classes/java/beans/MetaData.java b/jdk/src/share/classes/java/beans/MetaData.java index e2cb0326c69bc3bbfbcde912ee8391ae7384f388..5d8fd69791854a4b8ae765b7e08c93dd73d251c4 100644 --- a/jdk/src/share/classes/java/beans/MetaData.java +++ b/jdk/src/share/classes/java/beans/MetaData.java @@ -650,7 +650,7 @@ class java_util_Map_PersistenceDelegate extends DefaultPersistenceDelegate { // 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); diff --git a/jdk/test/java/beans/XMLEncoder/Test4994637.java b/jdk/test/java/beans/XMLEncoder/Test4994637.java new file mode 100644 index 0000000000000000000000000000000000000000..5476a8100bbf450d7a2c9960ba43b46eb8d291fd --- /dev/null +++ b/jdk/test/java/beans/XMLEncoder/Test4994637.java @@ -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 { + 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 { + public CustomMap() { + put("1", "one"); + put("2", "two"); + put("3", "three"); + } + } +} diff --git a/jdk/test/java/beans/XMLEncoder/java_util_HashMap.java b/jdk/test/java/beans/XMLEncoder/java_util_HashMap.java index 9a9771f80db20ec4cbf17bd0edc8d75dd21dc1b0..d9058003e4dfd21cb71a77013f6086d93cf53b92 100644 --- a/jdk/test/java/beans/XMLEncoder/java_util_HashMap.java +++ b/jdk/test/java/beans/XMLEncoder/java_util_HashMap.java @@ -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 @@ public final class java_util_HashMap extends AbstractTest> { new java_util_HashMap().test(true); } + @Override protected Map getObject() { - return new HashMap(); + Map map = new HashMap(); + map.put(null, null); + map.put("key", "value"); + map.put("key-null", "null-value"); + map.put("way", "remove"); + return map; } + @Override protected Map getAnotherObject() { Map map = new HashMap(); map.put(null, "null-value"); @@ -48,6 +55,7 @@ public final class java_util_HashMap extends AbstractTest> { return map; } + @Override protected void validate(Map before, Map after) { super.validate(before, after); validate(before); @@ -55,10 +63,18 @@ public final class java_util_HashMap extends AbstractTest> { } private static void validate(Map 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; } }