[
https://issues.apache.org/jira/browse/GROOVY-4862?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Eric Milles reassigned GROOVY-4862:
-----------------------------------
Assignee: Eric Milles
> 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
> Environment: Win7 64, JDK 1.6.0_17
> Reporter: Markus Günther
> Assignee: Eric Milles
> Priority: Major
> 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)