You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2026/02/03 22:04:00 UTC

[jira] [Resolved] (GROOVY-4862) propertyMissing / methodMissing called on outer instead of inner class

     [ https://issues.apache.org/jira/browse/GROOVY-4862?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eric Milles resolved GROOVY-4862.
---------------------------------
    Fix Version/s: 6.0.0-alpha-1
       Resolution: Fixed

https://github.com/apache/groovy/commit/ed63edb33fa81b660493e8924487a05ce0735a65

> propertyMissing / methodMissing called on outer instead of inner class
> ----------------------------------------------------------------------
>
>                 Key: GROOVY-4862
>                 URL: https://issues.apache.org/jira/browse/GROOVY-4862
>             Project: Groovy
>          Issue Type: Sub-task
>          Components: groovy-runtime
>    Affects Versions: 1.7.2, 1.7.10, 1.8.0
>            Reporter: Markus Günther
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 6.0.0-alpha-1
>
>         Attachments: Existing_PropertyMissing_Called_On_InnerClass_Spec.groovy
>
>
> I have an outer FactoryClass creating instances of an InnerClass:
> {code}
> class MyFactory {
>     static def createMyInner(String name) {
>       return new MyInnerClass(name)
>     }
>     static class MyInnerClass {
> //      def prop = "InnerProperty"
>       String name
>       MyInnerClass(String name) {
>         this.name = name
>       }
>     }
>   }
> {code}
> Now I create an Instance of MyInnerClass and try to access a non-existent property or method on it:
> {code}
>     def myImpl = MyFactory.createMyInner("InnerClass")
>     def prop = myImpl.prop
> {code}
> The following error occurs:
> {code}
>   groovy.lang.MissingFieldException: No such field: prop for class: MyFactory
> {code}
> When I uncomment the line
> {code}
>   def prop = "InnerProperty"
> {code}
> it is correctly resolved.
> But if I try to add propertyMissing() to my InnerClass:
> {code}
>     static class MyInnerClass {
>       ...
>       def propertyMissing(name) {
>         new MyInnerClass(name)
>       }
>       ...
>     }
> {code}
> the same error persists.
> I read (here: http://groovy.329449.n5.nabble.com/methodMissing-message-td4288343.html#a4305333) that inner classes will get an automatic propertyMissing() from the compiler, delegating to their outer class. Is this the root of the problem here?
> In my Opinion, several things should be changed here:
> 1) Existing propertyMissing()-implementations should not be disregarded (this is critical to me!) 
> 2) The error message should state correctly that InnerClass does not have the specified property
> 3) The same goes for methodMissing() (This is going to be critical for me verry soon, too!)
> The problem occurs regardless of MyFactory being a stand-alone class or an inner class of the executing code (f.e. test)
> I'm not good with jUnit, I hope Spock is fine, too.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)