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

ArrayStoreException assigning GStringImpl to String[] when using Indy

    XMLWordPrintableJSON

Details

    Description

      While upgrading a software baseline from Java 7/Groovy 2.0.2 to Java 8/Groovy 2.4, it appears that assigning a GString with an embedded variable reference to a String array is broken when using Indy. The following example demonstrates this issue:

      int a = 1
      String[] fubar = new String[1]
      fubar[0] = "Item $a"
      println fubar
      

      Without Indy, it works just fine:

      /c/test$ groovy GroovyIndyBug.groovy
      [Item 1]

      With Indy, we get the ArrayStoreException

      /c/test$ groovy -indy GroovyIndyBug.groovy
      Caught: java.lang.ArrayStoreException: org.codehaus.groovy.runtime.GStringImpl
      java.lang.ArrayStoreException: org.codehaus.groovy.runtime.GStringImpl
      at GroovyIndyBug.run(GroovyIndyBug.groovy:3)

      I tried various other assignment methods and this appears to be the only one with the issue. Oddly, even doing the same assignment, but at creation time instead of after, works just fine. Some of the other related scenarios I tried are:

      int a = 1
      
      String[] foo = ["Assigned At Creation $a"]
      println foo
      
      foo[0] = "No Embedded Variable"
      println foo
      
      foo[0] = "as String $a" as String
      println foo
      
      foo[0] = "BROKEN $a"
      println foo
      

      With Indy:

      /c/test $ groovy -indy GroovyIndyBug.groovy
      [Assigned At Creation 1]
      [No Embedded Variable]
      [as String 1]
      Caught: java.lang.ArrayStoreException: org.codehaus.groovy.runtime.GStringImpl
      java.lang.ArrayStoreException: org.codehaus.groovy.runtime.GStringImpl
      at GroovyIndyBug.run(GroovyIndyBug.groovy:12)

      Attachments

        Activity

          People

            paulk Paul King
            kenscoggins Ken Scoggins
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 0.5h
                0.5h