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

        Paul King made changes -
        Field Original Value New Value
        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.
        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:
        {code}
        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)");
            }
        }
        {code}
        Main class:
        {code}
        @Mixin(UtilClass)
        class MainClass {
            public static void main(String []s) {
                MainClass mc = new MainClass()
                mc.callMixinMethods()
            }

            void callMixinMethods() {
                callClassOverloadedMethod("")
                callStaticOverloadedMethod("")
            }
        }
        {code}
        Run command:
        {noformat}
        groovy -cp . MainClass
        {noformat}
        Error:
        {noformat}
        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)
        {noformat}

        Please fix this trouble, it prevent me to write code and tests.
        Roshan Dawrani made changes -
        Attachment Patch_Master.diff [ 56821 ]
        blackdrag blackdrag made changes -
        Assignee Jochen Theodorou [ blackdrag ] Roshan Dawrani [ roshandawrani ]
        Roshan Dawrani made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 1.8.3 [ 17657 ]
        Fix Version/s 1.9-beta-4 [ 17656 ]
        Resolution Fixed [ 1 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

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

            Dates

            • Created:
              Updated:
              Resolved: