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

ArrayList remove method not working, works another way

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 7u71
    • core-libs

      FULL PRODUCT VERSION :
      Version 7 Update 67 (build 1.7.0_67-b01)

      ADDITIONAL OS VERSION INFORMATION :
      ver Windows 8.1 64 bit

      A DESCRIPTION OF THE PROBLEM :
      ArrayList() was not getting smaller in size after I called myArrayList.remove(elementNumberSix); (which I think it should because I removed an element, and I'm worried it was still in the list and not removed) but was decreasing in size (and I'm assuming removed) if I removed the element like:

      card myCard = myArrayList.get(elementNumberSix);
      myArrayList.remove(myCard);

      ADDITIONAL REGRESSION INFORMATION:
      Version 7 Update 67 (build 1.7.0_67-b01)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      create an arraylist, add an element to it (my element was a custom object called card (a class)) and try to remove it with yourListName.remove, system.out.println() the size and see if it was removed, then try to remove it with
      card myCard = myArrayList.get(elementNumberSix);
      myArrayList.remove(myCard);

      print line the size and see if it was removed.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      the size remains one after removal

      the size is now zero and empty after removal
      ACTUAL -
      the size remains one after myArrayList.remove(); on one element

      the size is now zero and empty after removal using
      card myCard = myArrayList.get(elementNumberSix);
      myArrayList.remove(myCard);

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.*;
      class myClass{
      ArrayList<card> myList;
      public myClass{
      myList = new ArrayList<card>();
      myList.add(new card());
      myList.remove(0);
      System.out.println(myList.size());
      public static void Main(String[] args){
      new myClass();
      }
      }
      class card{
      public card(){

      }
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      import java.util.*;
      class myClass{
      ArrayList<card> myList;
      public myClass{
      myList = new ArrayList<card>();
      myList.add(new card());
      card myCard = ArrayList.get(0);
      ArrayList.remove(myCard);
      System.out.println(myList.size());
      public static void Main(String[] args){
      new myClass();
      }
      }
      class card{
      public card(){

      }
      }
      }

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: