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

ArrayStoreException assigning GStringImpl to String[] when using Indy

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.4.3
    • Fix Version/s: None
    • Component/s: groovy-runtime
    • Labels:
    • Environment:
      Windows 7; Java 8

      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

            • Assignee:
              Unassigned
              Reporter:
              kenscoggins Ken Scoggins
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: