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

ConcurrentSkipListSet.navigableHeadSet will not throw IllegalArgumentException for out of range

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Not an Issue
    • Affects Version/s: 6
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:

      Description

      ConcurrentSkipListSet.navigableHeadSet will not throw IllegalArgumentException for out of range.

      See the follwoing testcase :
      <testcase>
      import java.util.NavigableSet;
      import java.util.concurrent.ConcurrentSkipListSet;

      public class Test03 {
          @SuppressWarnings("unchecked")
          public static void main(String[] args) {
              final ConcurrentSkipListSet set = new ConcurrentSkipListSet();
              set.add(-1);
              set.add(0);
              set.add(1);
              NavigableSet ns = set.navigableHeadSet(1);
              try {
                  ns.add(1);
                  System.out.println("IllegalArgumentException is not thown for 1");
              } catch (IllegalArgumentException iae) {
                  System.out.println("IllegalArgumentException is thown for 1");
              }
              try {
                  ns.add(-2);
                  System.out.println("IllegalArgumentException is not thown for -2");
              } catch (IllegalArgumentException iae) {
                  System.out.println("IllegalArgumentException is thown for -2");
              }
          }
      }
      </testcase>
      <output>
      IllegalArgumentException is thown for 1
      IllegalArgumentException is not thown for -2
      </output>
      '1' is not in the range so it is fine but in the above case '-2' which is not in the range of 'set' but NavigableSet is able to add the same to set.
      According to spec,
      "The returned set will throw an IllegalArgumentException on an attempt to insert an element outside its range."
      In this case NavigableSet violates the spec behaviour since -2 is not the range.

      tried on windows XP:
      <java-version>
      java version "1.6.0-rc"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-rc-b64)
      Java HotSpot(TM) Client VM (build 1.6.0-rc-b64, mixed mode, sharing)
      </java-version>
      Same the case with navigableTailSet() also.

        Attachments

          Activity

            People

            Assignee:
            martin Martin Buchholz
            Reporter:
            savadhansunw Seetharama Avadhanam (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: