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

Object[] as List causes ClassCastException

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-JSR-5
    • 1.0
    • None
    • None
    • Ubuntu 5.10 Breezy Badger; Java SE 5 -- JDK 1.5.0_06-b05; Groovy CVS Head 2006-01-23 11:30

    Description

      The script:

      #! /usr/bin/env groovy

      def x = ( new File ( "." ) ).list ( )
      assert x instanceof String[]

      def y = x as List
      assert y instanceof List

      when executed, results in:

      Caught: java.lang.ClassCastException: [Ljava.lang.String;
      at testfile.run(testfile.groovy:6)
      at testfile.main(testfile.groovy)

      Clearly Groovy does not have direct support for coercion of Object[] to List using this syntax.

      replacing

      def y = x as List

      with

      def y = x.toList ( )

      makes the script work so the functionality is there. The issue is one of consistency of use of the "as List" type syntax.

      Attachments

        Activity

          People

            paulk Paul King
            russel Dr. Russel Winder
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: