Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8176192

Incorrect usage of Iterator in Java 8 In com.sun.jndi.ldap.EventSupport.removeNamingListener

    Details

    • Subcomponent:
    • Introduced In Version:
      8
    • Resolved In Build:
      b13
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Backports

        Description

        FULL PRODUCT VERSION :


        A DESCRIPTION OF THE PROBLEM :
        Class: com.sun.jndi.ldap.EventSupport

        IntelliJ decomplier code below code below:

        In jdk1.7.0_80 in rt.jar

            synchronized void removeNamingListener(NamingListener var1) {
                Enumeration var2 = this.notifiers.elements();

                while(var2.hasMoreElements()) {
                    NamingEventNotifier var3 = (NamingEventNotifier)var2.nextElement();
                    if(var3 != null) {
                        var3.removeNamingListener(var1);
                        if(!var3.hasNamingListeners()) {
                            var3.stop();
                            this.notifiers.remove(var3.info); -> Works fine, since it’s Enumeration and not iterator
                        }
                    }
                }

                if(this.unsolicited != null) {
                    this.unsolicited.removeElement(var1);
                }

            }



        jdk1.8.0_112 in rt.jar

            synchronized void removeNamingListener(NamingListener var1) {
                Iterator var2 = this.notifiers.values().iterator();

                while(var2.hasNext()) {
                    NamingEventNotifier var3 = (NamingEventNotifier)var2.next();
                    if(var3 != null) {
                        var3.removeNamingListener(var1);
                        if(!var3.hasNamingListeners()) {
                            var3.stop();
                            this.notifiers.remove(var3.info); -> Clearly an incorrect usage of iterator.. This throws a concurrent modification exception
                        }
                    }
                }

                if(this.unsolicited != null) {
                    this.unsolicited.removeElement(var1);
                }

            }



        REGRESSION. Last worked in version 7u80

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Remove listener without
        ACTUAL -
        Not removing listener

        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        java.util.ConcurrentModificationException: null
        at java.util.Hashtable$Enumerator.next(Hashtable.java:1378)
        at com.sun.jndi.ldap.EventSupport.removeNamingListener(EventSupport.java:211)
        at com.sun.jndi.ldap.LdapCtx.removeNamingListener(LdapCtx.java:3445)


        REPRODUCIBILITY :
        This bug can be reproduced always.

        CUSTOMER SUBMITTED WORKAROUND :
        Not use the remove listener metod

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  vtewari Vyom Tewari
                  Reporter:
                  webbuggrp Webbug Group
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  6 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: