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

Remove method is not throwing java.util.ConcurrentModificationException in List

    XMLWordPrintable

    Details

      Description

      FULL PRODUCT VERSION :
      jdk 8

      ADDITIONAL OS VERSION INFORMATION :
      all version

      A DESCRIPTION OF THE PROBLEM :
      package org.vc.testing;

      import java.util.ArrayList;
      import java.util.List;

      public class TestList {

      public static void main(String[] args) {
      // TODO Auto-generated method stub
      List<String> l = new ArrayList<String>();

      l.add("Mr.");
      l.add("Vikas");
      // l.add("Choudhary");
      for(String ll : l){
      l.remove(ll);
      System.out.println(ll);
      }
      }

      }


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      We are traversing over list and making modification. In case we are not using Iterator interface then program will throw java.util.ConcurrentModificationException . but If list contains only two elements, execution is fine without Iterator.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      If we are not using Iterator interface and making modification then It should throw java.util.ConcurrentModificationException .

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package org.vc.testing;

      import java.util.ArrayList;
      import java.util.List;

      public class TestList {

      public static void main(String[] args) {
      // TODO Auto-generated method stub
      List<String> l = new ArrayList<String>();

      l.add("Mr.");
      l.add("Vikas");
      //l.add("Choudhary");
      for(String ll : l){
      l.remove(ll);
      System.out.println(ll);
      }
      }

      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      For each operation on list you are increment modCount. In case we are not using Iterator interface then based on modCount and expectedmodCount, we should throw exception first time only. because code comparing these two count after removing.

      We should make changes in remove(Object a) method accordingly.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              psonal Pallavi Sonal (Inactive)
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: