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

j.u.CopyOnWriteArrayList.subList().subList() doesn't always throw IOOBE as expected

XMLWordPrintable

      Specification
      http://docs.oracle.com/javase/8/docs/api/java/util/List.html#subList-int-int-
      says:

      "Throws:
      IndexOutOfBoundsException - for an illegal endpoint index value (fromIndex < 0 || toIndex > size || fromIndex > toIndex)"

      However it doesn't happen for some lists, please see the following code:

      ---
              CopyOnWriteArrayList<Integer> list = new CopyOnWriteArrayList<>();
              list.add(1);
              list.add(2);
              list.add(3);
              list.add(4);
              list.add(5);
              List<Integer> newList = list.subList(1, list.size() - 1);
              int fromIndex = 2;
              int toIndex = 1;
              newList.subList(fromIndex, toIndex);
      ---

      No exception will be thrown though fromIndex > toIndex.

      The following new JCK8a test will be failing due to this:

      api/java_util/concurrent/CopyOnWriteArrayList/index.html#CopyOnWriteArrayList[testSubList3_IndexOutOfBoundsException]

      The problem is seen with JDK8, JDK8u5




            chegar Chris Hegarty
            dbessono Dmitry Bessonov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: