--- old/src/java.naming/share/classes/com/sun/jndi/ldap/EventSupport.java 2020-03-19 13:55:57.000000000 +0800 +++ new/src/java.naming/share/classes/com/sun/jndi/ldap/EventSupport.java 2020-03-19 13:55:57.000000000 +0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2020, 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 @@ -250,7 +250,12 @@ if (debug) { System.err.println("EventSupport.removeDeadNotifier: " + info.name); } - notifiers.remove(info); + if (notifiers != null) { + // Only do this if cleanup() not been triggered, otherwise here + // will throw NullPointerException since notifiers will be set to + // null in cleanup() + notifiers.remove(info); + } } /** @@ -329,6 +334,11 @@ */ synchronized void queueEvent(EventObject event, Vector vector) { + if (notifiers == null) { + // That means cleanup() already done, not queue event anymore, + // otherwise, new created EventQueue will not been cleanup. + return; + } if (eventQueue == null) eventQueue = new EventQueue(); --- old/test/jdk/com/sun/jndi/ldap/RemoveNamingListenerTest.java 2020-03-19 13:55:58.000000000 +0800 +++ new/test/jdk/com/sun/jndi/ldap/RemoveNamingListenerTest.java 2020-03-19 13:55:58.000000000 +0800 @@ -39,7 +39,7 @@ /** * @test - * @bug 8176192 + * @bug 8176192 8241130 * @summary Incorrect usage of Iterator in Java 8 In com.sun.jndi.ldap. * EventSupport.removeNamingListener * @modules java.naming