Groovy
  1. Groovy
  2. GROOVY-3873

adding methods to metaclass of interface not working

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: 1.7-beta-2
    • Fix Version/s: 1.6.6, 1.7-rc-1
    • Component/s: None
    • Labels:
      None
    • Environment:
      1.7-beta-2

      Description

      this worked with 1.6 but not with 1.7-beta-2 any longer:

      ExpandoMetaClass.enableGlobally()
      List.metaClass.methodMissing = { String name, args ->
          true
      }
      def list = []
      assert list.noSuchMethod()
      

        Activity

        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        3d 5h 27m 1 Roshan Dawrani 11/Nov/09 19:16
        Resolved Resolved Closed Closed
        27d 23h 1 Paul King 09/Dec/09 18:16
        Mark Thomas made changes -
        Workflow jira [ 12970511 ] Default workflow, editable Closed status [ 12978232 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12732840 ] Default workflow, editable Closed status [ 12744597 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Hide
        Roshan Dawrani added a comment -

        Another way of reproducing the issue is to run the JIRA example in 1.6's groovyconsole. There also it fails for the very same underlying reason - that when groovyconsole comes up, it uses ArrayLists making its MC get cached and after that point, even if the code run in the console was doing EMC.enableGlobally() and modifying the MC indirectly through the interface of ArrayList, the earlier cached MC was still being returned due to ClassInfo bug.

        Ok, now I am done with the explanation part!

        Show
        Roshan Dawrani added a comment - Another way of reproducing the issue is to run the JIRA example in 1.6's groovyconsole. There also it fails for the very same underlying reason - that when groovyconsole comes up, it uses ArrayLists making its MC get cached and after that point, even if the code run in the console was doing EMC.enableGlobally() and modifying the MC indirectly through the interface of ArrayList, the earlier cached MC was still being returned due to ClassInfo bug. Ok, now I am done with the explanation part!
        Hide
        Roshan Dawrani added a comment -

        I want to add here that the issue was not there due to any change in the groovy behavior from 1.6 to 1.7. It was just due to a little difference in the sequence of events in the code getting executed between 1.6/1.7.

        To reproduce the issue in 1.6, uncomment the first line in the example below.

        //[] << "Test"
        
        ExpandoMetaClass.enableGlobally()
        List.metaClass.methodMissing = { String name, args ->
            true
        }
        def list = []
        assert list.noSuchMethod()
        

        So, the use of statement [] << "Test" causes the MetaClassImpl to get cached in ClassInfo - and after that point, the behavior of 1.6 and 1.7 are same - as the ClassInfo bug was there in both the versions (which has been corrected under this JIRA).

        In 1.7, there is this built-in(and enabled) AST transformation called AstBuilderTransformation, which was making "[] << 'x'" kind of calls, making the MC get cached in ClassInfo and bringing in the difference in behavior.

        Show
        Roshan Dawrani added a comment - I want to add here that the issue was not there due to any change in the groovy behavior from 1.6 to 1.7. It was just due to a little difference in the sequence of events in the code getting executed between 1.6/1.7. To reproduce the issue in 1.6, uncomment the first line in the example below. //[] << "Test" ExpandoMetaClass.enableGlobally() List.metaClass.methodMissing = { String name, args -> true } def list = [] assert list.noSuchMethod() So, the use of statement [] << "Test" causes the MetaClassImpl to get cached in ClassInfo - and after that point, the behavior of 1.6 and 1.7 are same - as the ClassInfo bug was there in both the versions (which has been corrected under this JIRA). In 1.7, there is this built-in(and enabled) AST transformation called AstBuilderTransformation, which was making "[] << 'x'" kind of calls, making the MC get cached in ClassInfo and bringing in the difference in behavior.
        Roshan Dawrani made changes -
        Resolution Fixed [ 1 ]
        Fix Version/s 1.6.6 [ 15781 ]
        Fix Version/s 1.7-rc-1 [ 14666 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Hide
        Roshan Dawrani added a comment -

        Fixed

        Show
        Roshan Dawrani added a comment - Fixed
        Roshan Dawrani made changes -
        Field Original Value New Value
        Assignee Roshan Dawrani [ roshandawrani ]
        Dierk König created issue -

          People

          • Assignee:
            Roshan Dawrani
            Reporter:
            Dierk König
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development