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

Spread operator type conversion error

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.4.15
    • None
    • groovy-runtime
    • None

    Description

      Line 6 with spread operator throws runtime typecast exception:

      class Test {
          def test() {
              byte [] b = [0, 0] as byte[]
              Object [] oa = [b] as Object []
              method( oa[0] )
              method( *oa ) //Does not work
          }
          def method(byte[] bytes) {}
      }
      new Test().test()
      

       

      Result:

      Caught: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[0, 0]' with class 'java.util.ArrayList' to class 'java.lang.Byte'
      org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[0, 0]' with class 'java.util.ArrayList' to class 'java.lang.Byte'
      at Test.test(test.groovy:7)

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              piizei Petteri Johansson
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: