Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-1685

using ranges as list subscripts limited to existing list size

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.0
    • 1.1-beta-2
    • None
    • None
    • groovy-1.0 on jre1.6.0 on WinXP prof edn

    Description

      //Using both integers and ranges as list subscripts OK when within existing list size...
      list = ['a','b','c']; list[1] = 'x'; assert list == ['a','x','c']
      list = ['a','b','c']; list[3] = 'x'; assert list == ['a','b','c','x']
      list = ['a','b','c']; list[1..2] = ['x','y']; assert list == ['a','x','y']

      //but only integers OK when outside existing list size...
      list = ['a','b','c']; list[4] = 'x'; assert list == ['a','b','c',null,'x']

      //Ranges as list subscripts outside existing list size cause an out-of-bounds exception...
      list = ['a','b','c']; try

      { list[2..3] = ['x','y'] }

      catch(Throwable e)

      { assert e instanceof IndexOutOfBoundsException }
      list = ['a','b','c']; try{ list[4..5] = ['x','y'] }catch(Throwable e){ assert e instanceof IndexOutOfBoundsException }

      //The desired behavior is:
      list = ['a','b','c']; list[2..3] = ['x','y']; assert list == ['a','b','x','y']
      list = ['a','b','c']; list[4..5] = ['x','y']; assert list == ['a','b','c',null,'x','y']

      Attachments

        Activity

          People

            paulk Paul King
            gavingrover Gavin Grover
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: