提交 c008f652 编写于 作者: M malenkov

4994637: LTP: java.beans.java_util_Map_PersistenceDelegate: ConcurrentModificationException

Reviewed-by: peterz, loneid
上级 de015226
......@@ -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);
......
/*
* 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");
}
}
}
/*
* 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<Map<String, String>> {
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 @@ public final class java_util_HashMap extends AbstractTest<Map<String, String>> {
return map;
}
@Override
protected void validate(Map<String, String> before, Map<String, String> after) {
super.validate(before, after);
validate(before);
......@@ -55,10 +63,18 @@ public final class java_util_HashMap extends AbstractTest<Map<String, String>> {
}
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;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册