groovy
  1. groovy
  2. GROOVY-3873

adding methods to metaclass of interface not working

    Details

    • Type: Bug Bug
    • Status: Closed 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
    • Testcase included:
      yes
    • Number of attachments :
      0

      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

        Hide
        Roshan Dawrani added a comment -

        Fixed

        Show
        Roshan Dawrani added a comment - Fixed
        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.
        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!

          People

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

            Dates

            • Created:
              Updated:
              Resolved: