groovy
  1. groovy
  2. GROOVY-3299

Modifying meta-class has no effect in some cases

    Details

    • Type: Bug Bug
    • Status: Reopened Reopened
    • Priority: Critical Critical
    • Resolution: Unresolved
    • Affects Version/s: 1.6-rc-1
    • Fix Version/s: 3.0
    • Component/s: groovy-runtime
    • Labels:
      None
    • Testcase included:
      yes
    • Number of attachments :
      2

      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.

        Activity

        Hide
        Guillaume Laforge added a comment -

        Alex committed the fix on both 1.6 and 1.7 branches.

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

        Fix doesn't work for interfaces.

        Show
        Peter Ledbrook added a comment - Fix doesn't work for interfaces.
        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.
        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.
        Hide
        blackdrag blackdrag 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 blackdrag 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:
            Peter Ledbrook
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: