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

SC: byte[] and Byte[] typecasting issue

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.1
    • 2.0.2
    • Static compilation
    • None

    Description

      import groovy.transform.*
      
      @CompileStatic
      class Bug3 {
          String test() {
              def b = "foo".bytes
              new String(b)
          }
      }
      
      new Bug3().test()
      

      Static compilation is not happy with the above, thinking b is a Byte[] instead of byte[], yielding the following error:

      org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[B@727a9fa7' with class '[B' to class 'byte'
      	at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToNumber(DefaultTypeTransformation.java:146)
      	at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.byteUnbox(DefaultTypeTransformation.java:46)
      	at Bug3.test(ConsoleScript34:7)
      
      

      Whereas, if you explicitly type the variable with byte[] it's okay.

      Attachments

        Activity

          People

            melix Cédric Champeau
            guillaume Guillaume Sauthier
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: