Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-5989 Inner Class Issues
  3. GROOVY-5875

Cannot use DELEGATE_FIRST and delegates that are inner classes.

    Details

    • Type: Sub-task
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.6
    • Fix Version/s: 2.2.0-beta-2
    • Component/s: None
    • Labels:
      None

      Description

      The following code exhibits the problem:

      class Owner {
          Object delegate
          String ownerProp = "owner"
          
          void run() {
              def c = {
                  delegateProp = ownerProp
              }
              c.delegate = delegate
              c.resolveStrategy = Closure.DELEGATE_FIRST
              c()
              assert c.delegate.delegateProp == ownerProp
          }
      }
      
      class Delegate {
          String delegateProp = "delegate"
      }
      
      class Container {
          static class Delegate {
               String delegateProp = "delegate"
          }
      }
      
      // works fine
      new Owner(delegate: new Delegate()).run()
      
      
      // not work so fine: 
      // groovy.lang.MissingFieldException: No such field: ownerProp for class: Containergroovy.lang.MissingFieldException: No such field: ownerProp for class: Container
      new Owner(delegate: new Container.Delegate()).run()    
      

      The problem appears to be that when what is effectively “propertyMissing” (i.e. the generated impl) is called for a class that is an inner class, a MissingFieldException is thrown. Inside the implementation of Closure#getPropertyTryThese(…), there is no handling for MissingFieldException (only MissingPropertyException). My naive opinion is that it's wrong for a MissingFieldException to be thrown in the first place.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                asteingress Andre Steingress
                Reporter:
                ldaley Luke Daley
              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: