Details
-
Sub-task
-
Status: Open
-
Major
-
Resolution: Unresolved
-
None
-
None
-
None
Description
The next code snippet illustrates the problem:
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 :(
The last line throws a MissingFieldException.
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:
def obj = new Object() { def propertyMissing(String name) { "this is also ignored" } } obj.foo
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.
Attachments
Attachments
Issue Links
- is related to
-
GROOVY-4862 propertyMissing / methodMissing called on outer instead of inner class
- Open