groovy
  1. groovy
  2. GROOVY-5359

static propertyMissing catches inherited static methods

    Details

    • Type: Improvement Improvement
    • Status: Open Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: groovy-runtime
    • Labels:
      None
    • Testcase included:
      yes
    • Number of attachments :
      0

      Description

      When static missing properties are catched, the handler is called also when an inherited static method is called.

      It is not a serious problem, but it feels weird. Either it should be changed (if possible with reasonably small effort), or thoroughly documented.

      Also, it should be documented that if the handler throws a MissingPropertyException, it gets silently eaten up and the static method is called all right. On the other hand, any other exception goes all the way up to the user-level harness if any, which is generally rather undesirable.

      Here's a code sample which illustrates the problem, along with the proper exception thrown so as the method is properly called:

      class Foo {
       static def inheritedStaticMethod() {
         println "Allright, Kilroy's here"
       }
      }
      
      class Test extends Foo {
        static def main(av) {
          // need to catch all class-level missing properties
          Object.metaClass.static.propertyMissing={
            println "Property $it of ${delegate.simpleName} missing."
            // simulated 'found valid dynamic property' case
            if (it.startsWith('f')) return "(${delegate.simpleName}.$it OK)"
            // oops, we did not find valid d.p, so we 
            throw new MissingPropertyException("No valid DP for ${delegate.simpleName}.$it")
          }
          println "Checking the handler: ${Object.foo} ${Foo.foo} ${Test.foo} ${String.foo}"
          inheritedStaticMethod()
        }
      }
      

        Activity

        No work has yet been logged on this issue.

          People

          • Assignee:
            Unassigned
            Reporter:
            OC
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: