--- old/src/java.naming/share/classes/com/sun/jndi/ldap/EventSupport.java 2017-06-13 12:10:01.113100098 +0530 +++ new/src/java.naming/share/classes/com/sun/jndi/ldap/EventSupport.java 2017-06-13 12:10:00.961100257 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2017, Oracle and/or its affiliates. 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 @@ -28,6 +28,8 @@ import java.util.Hashtable; import java.util.Vector; import java.util.EventObject; +import java.util.Iterator; +import java.util.Map; import javax.naming.*; import javax.naming.event.*; @@ -204,31 +206,37 @@ * Removes {@code l} from all notifiers in this context. */ synchronized void removeNamingListener(NamingListener l) { - if (debug) System.err.println("EventSupport removing listener"); - + if (debug) { + System.err.println("EventSupport removing listener"); + } // Go through list of notifiers, remove 'l' from each. // If 'l' is notifier's only listener, remove notifier too. - for (NamingEventNotifier notifier : notifiers.values()) { + Iterator> allnotifiers; + allnotifiers = notifiers.entrySet().iterator(); + while (allnotifiers.hasNext()) { + Map.Entry entry = allnotifiers.next(); + NamingEventNotifier notifier = entry.getValue(); if (notifier != null) { - if (debug) + if (debug) { System.err.println("EventSupport removing listener from notifier"); + } notifier.removeNamingListener(l); if (!notifier.hasNamingListeners()) { - if (debug) + if (debug) { System.err.println("EventSupport stopping notifier"); + } notifier.stop(); - notifiers.remove(notifier.info); + allnotifiers.remove(); } } } - // Remove from list of unsolicited notifier - if (debug) System.err.println("EventSupport removing unsolicited: " + - unsolicited); + if (debug) { + System.err.println("EventSupport removing unsolicited: " + unsolicited); + } if (unsolicited != null) { unsolicited.removeElement(l); } - } synchronized boolean hasUnsolicited() {