Grails
  1. Grails
  2. GRAILS-8800

GroovyCastException thrown when casting null using Groovy "as" operator

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: 2.0.1
    • Fix Version/s: 2.0.2
    • Component/s: Commons
    • Labels:
      None
    • Environment:
      Java 1.6 b29, Grails 2.0.1, Mac OS X 10.7.3
    • Testcase included:
      yes

      Description

      When casing a null value (either directly, or the result of a calculation) using the Groovy "as" operator, a GroovyCastException is thrown.

      I had trouble reproducing this initially, and I don't yet know the root cause, but I have been able to get a reproducable project with minimal code changes. The attached project is just the result of:

      0. Using Grails 2.0.1
      1. Run grails create-app
      2. Remove dependency to the resources plugin
      3. Run grails create-controller
      4. Add a controller method with "1 as Long" as well as rendering some text (just so if it does succeed we see something)

      The behavior is quite odd when it does or does not occur (but is deterministic in a given situation)

      -Only occurs when WAR'd up, never in run-app.
      -Occurs when running as run-war, and deployed to a tomcat 6 or 7 instance
      -Occurs whenever there is a null cast using "as" to a type (e.g. null as Long)
      -Does not occur when doing regular casting (e.g. (Long)null), or when assigning a null value to a strongly-typed variable (e.g. Long x = null)

      Add to that list now with this attached project:
      -Occurs in a clean grails project if the dependency to the resources plugin is removed

        Activity

        Michael Cameron created issue -
        Graeme Rocher made changes -
        Field Original Value New Value
        Fix Version/s 2.0.2 [ 13064 ]
        Priority Major [ 3 ] Blocker [ 1 ]
        Graeme Rocher made changes -
        Assignee Graeme Rocher [ graemerocher ]
        Graeme Rocher made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Graeme Rocher made changes -
        Status In Progress [ 3 ] Closed [ 6 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Graeme Rocher
            Reporter:
            Michael Cameron
          • Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development