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

Improper Implementation of hasNext method in ArrayList Class

XMLWordPrintable

      A DESCRIPTION OF THE PROBLEM :
      public boolean hasNext() {
           return cursor != size;
      }
      In this method we are checking cursor !=size, It will logically work fine but internally if somehow in future created new method which changes cursor variable manually, and after increasing it to more than size of ArrayList it will also return true, which cause affect to the purpose of this method. So we need to change instead to cursor<size .

      REGRESSION : Last worked in version 24.0.1

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      public boolean hasNext() {
           return cursor != size;
      }
      Change cursor to size+1 or more internally

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      false

      ---------- BEGIN SOURCE ----------
      Logical change
      ---------- END SOURCE ----------

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

              Created:
              Updated: