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

MissingFieldException when accessing @Lazy property of outer class

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.5
    • 2.4.0-beta-4
    • xforms
    • None

    Description

      If an inner class tries to access a @Lazy property of its outer class it will cause a MissingFieldException unless it either explicitly calls the getter or specifies the outer this.

      class Outer
      {
          @Lazy lazy   = 'lazy'
          final normal = 'normal'
          final inner  = new Inner()
          
          class Inner
          {
              def f() { normal }
              def g() { Outer.this.lazy }
              def h() { getLazy() }
              def i() { lazy }
          }
      }
      
      final outer = new Outer()
      
      assert outer.normal == outer.inner.f()
      assert outer.lazy   == outer.inner.g()
      assert outer.lazy   == outer.inner.h()
      assert outer.lazy   == outer.inner.i()
      

      The expected behavior is that #g, #h and #i are equivalent.

      Attachments

        Activity

          People

            Unassigned Unassigned
            justin.piper@gmail.com Justin Piper
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: