3977N/A/*
4248N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3977N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3977N/A *
3977N/A * This code is free software; you can redistribute it and/or modify it
3977N/A * under the terms of the GNU General Public License version 2 only, as
3977N/A * published by the Free Software Foundation.
3977N/A *
3977N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3977N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3977N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3977N/A * version 2 for more details (a copy is included in the LICENSE file that
3977N/A * accompanied this code).
3977N/A *
3977N/A * You should have received a copy of the GNU General Public License version
3977N/A * 2 along with this work; if not, write to the Free Software Foundation,
3977N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3977N/A *
3977N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3977N/A * or visit www.oracle.com if you need additional information or have any
3977N/A * questions.
3977N/A */
3977N/A
3977N/A/*
3977N/A * Portions Copyright (c) 2011 IBM Corporation
3977N/A */
3977N/A
3977N/A/*
3977N/A * @test
3977N/A * @bug 6312706
3977N/A * @summary Iterator.remove() from Map.entrySet().iterator() invalidates returned Entry.
3977N/A * @author Neil Richards <neil.richards@ngmr.net>, <neil_richards@uk.ibm.com>
3977N/A */
3977N/A
3977N/Aimport java.util.EnumMap;
3977N/Aimport java.util.Iterator;
3977N/Aimport java.util.Map;
3977N/A
3977N/Apublic class EntrySetIteratorRemoveInvalidatesEntry {
3977N/A static enum TestEnum { e00, e01, e02 }
3977N/A
3977N/A public static void main(String[] args) throws Exception {
3977N/A final EnumMap<TestEnum, String> enumMap = new EnumMap<>(TestEnum.class);
3977N/A
3977N/A for (TestEnum e : TestEnum.values()) {
3977N/A enumMap.put(e, e.name());
3977N/A }
3977N/A
3977N/A Iterator<Map.Entry<TestEnum, String>> entrySetIterator =
3977N/A enumMap.entrySet().iterator();
3977N/A Map.Entry<TestEnum, String> entry = entrySetIterator.next();
3977N/A
3977N/A entrySetIterator.remove();
3977N/A
3977N/A try {
3977N/A entry.getKey();
3977N/A throw new RuntimeException("Test FAILED: Entry not invalidated by removal.");
3977N/A } catch (Exception e) { }
3977N/A }
3977N/A}