groovy
  1. groovy
  2. GROOVY-4999

Runtime error on static overloaded mixin method

    Details

    • Testcase included:
      yes
    • Number of attachments :
      1

      Description

      I have a class with static utility methods. I have done 'mixin' this class into another class using @Mixin annotation and then while calling static overloaded method I give runtime error.

      Utility class:

      class UtilClass {
          public void callClassOverloadedMethod(String s) {
              System.out.println("callClassOverloadedMethod(String)");
          }
          public void callClassOverloadedMethod(String s, Object o) {
              System.out.println("callClassOverloadedMethod(String, Object)");
          }
          public static void callStaticOverloadedMethod(String s) {
              System.out.println("callStaticOverloadedMethod(String)");
          }
          public static void callStaticOverloadedMethod(String s, Object o) {
              System.out.println("callStaticOverloadedMethod(String, Object)");
          }
      }
      

      Main class:

      @Mixin(UtilClass)
      class MainClass {
          public static void main(String []s) {
              MainClass mc = new MainClass()
              mc.callMixinMethods()
          }
      
          void callMixinMethods() {
              callClassOverloadedMethod("")
              callStaticOverloadedMethod("")
          }
      }
      

      Run command:

      groovy -cp . MainClass
      

      Error:

      Caught: org.codehaus.groovy.runtime.metaclass.MethodSelectionException: Could not find which method callStaticOverloadedMethod() to invoke from this list:
        public static void UtilClass#callStaticOverloadedMethod(java.lang.String)
        public static void UtilClass#callStaticOverloadedMethod(java.lang.String, java.lang.Object)
              at MainClass.callMixinMethod(MainClass.groovy:20)
              at MainClass.main(MainClass.groovy:12)
      

      Please fix this trouble, it prevent me to write code and tests.

        Activity

        Hide
        Paul King added a comment -

        add code tags

        Show
        Paul King added a comment - add code tags
        Hide
        Roshan Dawrani added a comment -

        Attached patch with a suggested fix.

        Works with the test case provided (will add it formally if the fix looks ok).

        Show
        Roshan Dawrani added a comment - Attached patch with a suggested fix. Works with the test case provided (will add it formally if the fix looks ok).
        Hide
        blackdrag blackdrag added a comment -

        feel free to commit

        Show
        blackdrag blackdrag added a comment - feel free to commit
        Hide
        Anton Spirin added a comment -

        Thanks! This patch works for me. When can I see changes in production release?

        Show
        Anton Spirin added a comment - Thanks! This patch works for me. When can I see changes in production release?
        Hide
        Roshan Dawrani added a comment -

        The daily snapshots should include this patch by tonight (http://snapshots.repository.codehaus.org/org/codehaus/groovy/groovy-all/)

        Show
        Roshan Dawrani added a comment - The daily snapshots should include this patch by tonight ( http://snapshots.repository.codehaus.org/org/codehaus/groovy/groovy-all/ )
        Hide
        blackdrag blackdrag added a comment -

        But you did not yet commit Roshan, did you?

        Show
        blackdrag blackdrag added a comment - But you did not yet commit Roshan, did you?
        Hide
        Roshan Dawrani added a comment -

        No. That's why I said it will be there by tonight, otherwise the snapshot-with-the-fix would have already been there

        Not near my computer at the moment. Will be in a couple of hours.

        Show
        Roshan Dawrani added a comment - No. That's why I said it will be there by tonight, otherwise the snapshot-with-the-fix would have already been there Not near my computer at the moment. Will be in a couple of hours.

          People

          • Assignee:
            Roshan Dawrani
            Reporter:
            Anton Spirin
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: