JDK-8041343 : j.u.CopyOnWriteArrayList.subList().subList() doesn't always throw IOOBE as expected
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.concurrent
  • Affected Version: 8u11
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2014-04-21
  • Updated: 2014-04-21
  • Resolved: 2014-04-21
Related Reports
Duplicate :  
Description
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





Comments
This issue would appear to be a duplicate of JDK-8011645. If so, then this issue should be closed as such, and JDK-8011645 be backported to JDK 8u-dev.
21-04-2014