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

java.util.Collections.lastIndexOfSubList()

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.4.0
    • core-libs
    • beta2
    • x86
    • windows_nt
    • Verified

      java.util.Collections.lastIndexOfSubList(List source, List target)

      when target.size() > source.size() expected return value is -1

      case when target.size source.size() returns
      -------------------------------------------------
       1. 10 9 -1

       2. 100 99 IndexOutOfBoundsException thrown


      I am attaching two test files.
      Test.java case 1
      TestLarge.java case 2
      result.txt output of both Test.java and TestLarge.java
               -----------

      /**
       *
       *lastIndexOfSubListBugTest01: java.util.Collections static int lastIndexOfSubList(List source, List target)
       *
       */
      import java.util.*;

      public class Test {
          public static void main(String[] args) {
              try {
                      
                   List listOrg = new LinkedList();
                   for (int i=1; i<10; i++) {
                       listOrg.add(new Integer(i));
                   }

                   List subList = new LinkedList();
                   for (int i=1; i<11; i++) {
                       subList.add(new Integer(i));
                   }
                   System.out.println("listOrg = " + listOrg);
                   System.out.println("subList = " + subList);
                   System.out.println("listOrg.size = " + listOrg.size());
                   System.out.println("subList.size = " + subList.size());
                   //int index = Collections.indexOfSubList(listOrg,subList);
                   //System.out.println("Collections.indexOfSubList(listOrg,subList) = " + index);
                   
                   int index1 = Collections.lastIndexOfSubList(listOrg,subList);
                   System.out.println("Collections.lastIndexOfSubList(listOrg,subList) = " + index1);
                    
              } catch(Exception e) {
                  System.out.println("Exception thrown = " + e);
                  System.out.println("LastIndexOfSubListTest03() Fail");
                  e.printStackTrace();
              }
        
          }
       }
       -------------------------------------
       

      /**
       *
       *lastIndexOfSubListBugTest01: java.util.Collections static int lastIndexOfSubList(List source, List target)
       *
       */
      import java.util.*;

      public class TestLarge {
          public static void main(String[] args) {
              try {
                      
                   List listOrg = new LinkedList();
                   for (int i=1; i<100; i++) {
                       listOrg.add(new Integer(i));
                   }

                   List subList = new LinkedList();
                   for (int i=1; i<101; i++) {
                       subList.add(new Integer(i));
                   }
                   System.out.println("listOrg = " + listOrg);
                   System.out.println("subList = " + subList);
                   System.out.println("listOrg.size = " + listOrg.size());
                   System.out.println("subList.size = " + subList.size());
                   //int index = Collections.indexOfSubList(listOrg,subList);
                   //System.out.println("Collections.indexOfSubList(listOrg,subList) = " + index);
                   
                   int index1 = Collections.lastIndexOfSubList(listOrg,subList);
                   System.out.println("Collections.lastIndexOfSubList(listOrg,subList) = " + index1);
                    
              } catch(Exception e) {
                  System.out.println("Exception thrown = " + e);
                  System.out.println("LastIndexOfSubListTestLage03() Fail");
                  e.printStackTrace();
              }
        
          }
       }
       --------------------------------------
      H:\merlin\dev\testbase\src\libs_api_tests\common\java_util\Collections\LastIndexOfSubListBug>java Test
      listOrg = [1, 2, 3, 4, 5, 6, 7, 8, 9]
      subList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
      listOrg.size = 9
      subList.size = 10
      Collections.lastIndexOfSubList(listOrg,subList) = -1

      H:\merlin\dev\testbase\src\libs_api_tests\common\java_util\Collections\LastIndexOfSubListBug>javac TestLarge.java

      H:\merlin\dev\testbase\src\libs_api_tests\common\java_util\Collections\LastIndexOfSubListBug>java TestLarge
      listOrg = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]
      subList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
      listOrg.size = 99
      subList.size = 100
      Exception thrown = java.lang.IndexOutOfBoundsException: Index: -1, Size: 99
      LastIndexOfSubListTestLage03() Fail
      java.lang.IndexOutOfBoundsException: Index: -1, Size: 99
              at java.util.LinkedList$ListItr.<init>(LinkedList.java:459)
              at java.util.LinkedList.listIterator(LinkedList.java:448)

            jjb Josh Bloch (Inactive)
            spandeorcl Shantaram Pande (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: