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

SC: property access within closure produces cast exception

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.0.12
    • 4.0.12
    • Static compilation
    • None

    Description

      Consider the following:

      class Bar {
        @groovy.beans.Bindable
        String baz
        String other
      }
      class Foo {
        Bar bar
        @groovy.beans.Bindable
        String foo
        @groovy.transform.CompileStatic
        void postConstruct() {
          bar = new Bar()
          bar.with {
            addPropertyChangeListener('baz') { event ->
              other = 'value' // ClassCastException: class Foo cannot be cast to class Bar
              print 'changed'
            }
          }
          print 'ready;'
        }
      }
      
      Foo foo = new Foo()
      foo.postConstruct()
      foo.getBar().setBaz('xxx')
      

      Attachments

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            emilles Eric Milles
            emilles Eric Milles
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment