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

Bug in the constructor of anonymous inner class

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3.1
    • 2.3.3
    • None
    • None

    Description

      Test example:

        class CreatePaymentPanel {
            def foo() { new SomeFragment() {} }
            class SomeFragment {}
        }
        new CreatePaymentPanel().foo()
      

      Going through the AST I think I located the problem. Inner class is
      generated as:

      public class CreatePaymentPanel$SomeFragment {
          public CreatePaymentPanel this$0
      
          public CreatePaymentPanel$SomeFragment(CreatePaymentPanel $p$) {
              super()
              this$0 = $p$
          }
      }
      

      so far so good. Anonymous inner class looks like this:

      public class CreatePaymentPanel$1 extends CreatePaymentPanel$SomeFragment {
          public CreatePaymentPanel this$0
      
          public CreatePaymentPanel$1(CreatePaymentPanel p0) {
              super()
              this$0 = p0
          }
      }
      

      and method foo:

        public Object foo() {
            new CreatePaymentPanel$1(this)
        }
      

      The problem lies in `CreatePaymentPanel$1`'s constructor, in
      particular its call of `super()`. Its superclass
      `CreatePaymentPanel$SomeFragment` defines one constructor with
      `CreatePaymentPanel` instance as parameter. If `CreatePaymentPanel$1`
      called `super(p0)` all would be fine.

      Attachments

        Activity

          People

            melix Cédric Champeau
            bura Andrey Bloschetsov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: