1. Groovy
  2. GROOVY-2503 MOP 2.0 design inflluencing issues
  3. GROOVY-1826

Stop requiring exceptions in MetaClass to indicate method/property does not exist


    • Type: Sub-task Sub-task
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.0
    • Fix Version/s: None
    • Component/s: groovy-runtime
    • Labels:


      Currently the MetaClass mechanism has no clean way for a descendent metaclass or runtime code to know if a property or method exists - including those dynamically intercepted/provided by the metaclass.

      This means you have to rely on exceptions and this is very costly in performance terms in a multi threaded environment.


      This is a Grails issue with code attached for a workaround for the lack of a hasProperty, hasMethod and hasClosure method on MetaClass. It is ugly but it works, by caching the result of invocations / pickMethod and encoding some special behaviour related to closures. This duplicates/mutates logic currently in MetaClassImpl.invokeMethod() which is a bad thing.

      We have seen a 30-50% speed increase in serving Grails pages in concurrent tests after using this new metaclass, instead of catching MissingMethodException and MissingPropertyException.

      Also I believe that MetaClass should have invokeClosure on it, and remove some of the closure calling logic from invokeMethod, as this makes for a cleaner separation.

        Issue Links


          Jochen Theodorou made changes -
          Assignee Jochen Theodorou [ blackdrag ]
          Mark Thomas made changes -
          Workflow jira [ 12973956 ] Default workflow, editable Closed status [ 12981145 ]
          Mark Thomas made changes -
          Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
          Mark Thomas made changes -
          Workflow jira [ 12730942 ] Default workflow, editable Closed status [ 12742869 ]
          Mark Thomas made changes -
          Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
          Jochen Theodorou made changes -
          Component/s groovy-runtime [ 16250 ]
          Jochen Theodorou made changes -
          Issue Type New Feature [ 2 ] Sub-task [ 7 ]
          Parent GROOVY-2503 [ 61571 ]
          Jochen Theodorou made changes -
          Link This issue depends upon GROOVY-2503 [ GROOVY-2503 ]
          Jochen Theodorou made changes -
          Field Original Value New Value
          Assignee Jochen Theodorou [ blackdrag ]
          Marc Palmer created issue -


            • Assignee:
              Marc Palmer
            • Votes:
              0 Vote for this issue
              0 Start watching this issue


              • Created: