Groovy
  1. Groovy
  2. GROOVY-3299

Modifying meta-class has no effect in some cases

    Details

    • Type: Bug Bug
    • Status: Reopened
    • Priority: Critical Critical
    • Resolution: Unresolved
    • Affects Version/s: 1.6-rc-1
    • Fix Version/s: 3.0
    • Component/s: groovy-runtime
    • Labels:
      None

      Description

      See the attach test case. Basically it seems that the meta class for a class is cached, but if it is modified (for example via EMC syntax), the cached version is not updated.

      1. MetaClassCachingBugTests.groovy
        0.6 kB
        Peter Ledbrook
      2. MetaClassCachingBugWithInterfaceTests.groovy
        0.6 kB
        Peter Ledbrook

        Activity

        Peter Ledbrook created issue -
        Hide
        Guillaume Delcroix added a comment -

        Alex committed the fix on both 1.6 and 1.7 branches.

        Show
        Guillaume Delcroix added a comment - Alex committed the fix on both 1.6 and 1.7 branches.
        Guillaume Delcroix made changes -
        Field Original Value New Value
        Fix Version/s 1.7-beta-1 [ 14014 ]
        Status Open [ 1 ] Closed [ 6 ]
        Resolution Fixed [ 1 ]
        Assignee Alex Tkachman [ ait ]
        Hide
        Peter Ledbrook added a comment -

        Fix doesn't work for interfaces.

        Show
        Peter Ledbrook added a comment - Fix doesn't work for interfaces.
        Peter Ledbrook made changes -
        Resolution Fixed [ 1 ]
        Status Closed [ 6 ] Reopened [ 4 ]
        Hide
        Peter Ledbrook added a comment -

        Slight variation on the original test case using the meta-class of CharSequence rather than String.

        Show
        Peter Ledbrook added a comment - Slight variation on the original test case using the meta-class of CharSequence rather than String.
        Peter Ledbrook made changes -
        Attachment MetaClassCachingBugWithInterfaceTests.groovy [ 39441 ]
        Guillaume Delcroix made changes -
        Fix Version/s 1.6-rc-2 [ 13832 ]
        Fix Version/s 1.6.1 [ 14852 ]
        Guillaume Delcroix made changes -
        Fix Version/s 1.6.2 [ 15151 ]
        Fix Version/s 1.6.1 [ 14852 ]
        Guillaume Delcroix made changes -
        Fix Version/s 1.6.2 [ 15151 ]
        Fix Version/s 1.6.3 [ 15251 ]
        Guillaume Delcroix made changes -
        Fix Version/s 1.6.3 [ 15251 ]
        Guillaume Delcroix made changes -
        Fix Version/s 1.7-beta-x [ 15538 ]
        Fix Version/s 1.7-beta-1 [ 14014 ]
        Jochen Theodorou made changes -
        Assignee Alex Tkachman [ ait ]
        Hide
        Paul King added a comment -

        The test case seems to work for me on both the 1_7_X branch and trunk. Peter, are you still having issues?

        Show
        Paul King added a comment - The test case seems to work for me on both the 1_7_X branch and trunk. Peter, are you still having issues?
        Hide
        Peter Ledbrook added a comment -

        I'm seeing it with Groovy 1.7.6. If I have time, I'll try to get hold of the 1.7.x branch and test that.

        Show
        Peter Ledbrook added a comment - I'm seeing it with Groovy 1.7.6. If I have time, I'll try to get hold of the 1.7.x branch and test that.
        Jochen Theodorou made changes -
        Fix Version/s 1.8.x [ 15750 ]
        Fix Version/s 2.x [ 17013 ]
        Fix Version/s 1.7.x [ 15538 ]
        Hide
        Jochen Theodorou added a comment -

        Still an issue with:

        StringMocker.mockString("test")
        def collaborator = new MyCollaborator()
        assert "test" == collaborator.getDummy("testOne")
        
        StringMocker.mockString("dog")
        collaborator = new MyCollaborator()
        assert "dog" == collaborator.getDummy("testTwo")
        
        
        class MyCollaborator {
           String getDummy(String str) {
               return str.dummy()
           }
        }
        
        class StringMocker {
           static mockString(String retval) {
               CharSequence.metaClass.dummy = {->
                   return retval
               }
           }
        }
        
        Show
        Jochen Theodorou added a comment - Still an issue with: StringMocker.mockString( "test" ) def collaborator = new MyCollaborator() assert "test" == collaborator.getDummy( "testOne" ) StringMocker.mockString( "dog" ) collaborator = new MyCollaborator() assert "dog" == collaborator.getDummy( "testTwo" ) class MyCollaborator { String getDummy( String str) { return str.dummy() } } class StringMocker { static mockString( String retval) { CharSequence.metaClass.dummy = {-> return retval } } }
        Jochen Theodorou made changes -
        Fix Version/s 1.8.x [ 15750 ]
        Fix Version/s 3.0 [ 13489 ]
        Fix Version/s 2.x [ 17013 ]
        Jochen Theodorou made changes -
        Component/s groovy-runtime [ 16250 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Mark Thomas made changes -
        Workflow jira [ 12732296 ] Default workflow, editable Closed status [ 12744088 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12970117 ] Default workflow, editable Closed status [ 12977892 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Closed Closed
        49m 2s 1 Guillaume Delcroix 19/Jan/09 11:39
        Closed Closed Reopened Reopened
        14h 33m 1 Peter Ledbrook 20/Jan/09 02:13

          People

          • Assignee:
            Unassigned
            Reporter:
            Peter Ledbrook
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:

              Development