Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-3299

Modifying meta-class has no effect in some cases

    Details

    • Type: Bug
    • Status: Reopened
    • Priority: Critical
    • Resolution: Unresolved
    • Affects Version/s: 1.6-rc-1
    • Fix Version/s: 3.x
    • 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. MetaClassCachingBugWithInterfaceTests.groovy
        0.6 kB
        Peter Ledbrook
      2. MetaClassCachingBugTests.groovy
        0.6 kB
        Peter Ledbrook

        Activity

        Hide
        Guillaume Guillaume Delcroix added a comment -

        Alex committed the fix on both 1.6 and 1.7 branches.

        Show
        Guillaume Guillaume Delcroix added a comment - Alex committed the fix on both 1.6 and 1.7 branches.
        Hide
        pledbrook Peter Ledbrook added a comment -

        Fix doesn't work for interfaces.

        Show
        pledbrook Peter Ledbrook added a comment - Fix doesn't work for interfaces.
        Hide
        pledbrook Peter Ledbrook added a comment -

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

        Show
        pledbrook Peter Ledbrook added a comment - Slight variation on the original test case using the meta-class of CharSequence rather than String.
        Hide
        paulk 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
        paulk 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
        pledbrook 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
        pledbrook 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.
        Hide
        blackdrag 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
        blackdrag 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 } } }

          People

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

            Dates

            • Created:
              Updated:

              Development