groovy
  1. groovy
  2. GROOVY-5030

Calling a method overwritten via metaClass from another method uses the original (non-overwritten) method if the overridden class extends something

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.2
    • Fix Version/s: 1.8.3, 1.9-beta-4
    • Component/s: primtive opts
    • Labels:
      None
    • Testcase included:
      yes
    • Number of attachments :
      0

      Description

      Hi Everyone

      I'm using Groovy 1.8.2, and there's a variant of http://jira.codehaus.org/browse/GROOVY-4884. This code fails for me:

      import org.junit.Test;
      
      public class BreakingExample_NoMetaclassOverride {
         @Test
         void testNotOverriden() {
            def list = []
            ClassUnderTest cut = new ClassUnderTest()
            cut.metaClass.getRemoteObject = { ->
               return [method: {obj -> 
                  list << obj
               }] as RemoteObject
            }
            
            String val = "Value" 
            cut.someMethod(val)
            assert list == [val]
         }
      }
      
      public class ClassUnderTest extends RemoteObject {
         public def someMethod(String someValue) {
            RemoteObject object = getRemoteObject()
            object.method(someValue)
         }
         protected RemoteObject getRemoteObject() {
            return new RemoteObject()
         }
      }
      
      public class RemoteObject {
         public void method(obj) { /* Something */ }
      }
      

      The only difference between this and #4884 is the "extends RemoteObject" added to ClassUnderTest. With it in, the test fails. Remove it, the test passes.

      Please let me know if you need any more info!

      Thanks
      Jason Griffith

        Activity

        No work has yet been logged on this issue.

          People

          • Assignee:
            Roshan Dawrani
            Reporter:
            Jason Griffith
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: