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

Calling a method overwritten via metaClass from another method uses the original (non-overwritten) method

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.8.0
    • 1.8.1
    • primtive opts
    • None

    Description

      Having the following code...

      class A {
          String m1() { println 'called m1'; 'm1' }
          String m2() { println 'called m2'; println m1(); 'm2' }
      }
      a = new A()                                                                                                   
      a.metaClass.m1 = { -> println 'pwned m1'; 'o-m1' }                                                            
      

      Calling a.m2() shows...

      called m2
      called m1
      m1
      ===> m2
      

      ...but expected is this:

      called m2
      pwned m1
      o-m1
      ===> m2
      

      The correct output is shown in Groovy 1.7.x, only Groovy 1.8.0 shows the wrong one.

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            rene.scheibe Rene Scheibe
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: