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

Eric Milles updated GROOVY-4737:
--------------------------------
    Language: groovy

> propertyMissing not called in anonymous or inner classes
> --------------------------------------------------------
>
>                 Key: GROOVY-4737
>                 URL: https://issues.apache.org/jira/browse/GROOVY-4737
>             Project: Groovy
>          Issue Type: Sub-task
>          Components: groovy-runtime
>            Reporter: Demian Ferreiro
>            Priority: Major
>         Attachments: Groovy4737.groovy, propertyMissing.groovy
>
>
> The next code snippet illustrates the problem:
> {code}
> class Foo {
>     def propertyMissing(String name) { "missing $name" }
>     def getBar() { "bar" }
> }
> def f = new Foo()
> assert f.bar == "bar"
> assert f.baz == "missing baz" // porpertyMissing is called.
> def f2 = new Foo() {
>     def getFoobar() { "foobar" }
> }
> assert f2.foobar == "foobar" // This works ok.
> assert f2.bar == "bar" // This works too.
> assert f2.baz == "missing baz" // This breaks :(
> {code}
> The last line [throws a MissingFieldException|http://ideone.com/tJZ6l].
> If instead of using an anonymous class for the f2 variable a normal class 
> that extends Foo is used, the propertyMissing method is called correctly.
> No inheritance is required. If an anonymous class is defined as:
> {code}
> def obj = new Object() {
>     def propertyMissing(String name) { "this is also ignored" }
> }
> obj.foo
> {code}
> The MissingFieldException is also thrown.
> This also happens with inner classes. I think this behavior is unexpected, 
> because one would think that the only difference between an inner class and a 
> normal one is that an instance on the first one can access the fields and 
> methods of it's enclosing object.



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

Reply via email to