Groovy
  1. Groovy
  2. GROOVY-2409

Problems calling private static methods

    Details

      Description

      Like Java, Groovy allows for static methods to be called in different ways. Surprisingly, not all of them work for private static methods. Specifically:

      class Test { 
        // all errors go away if method is declared non-private 
        private static foo() {} 
        
        static callFooFromStaticMethod() { 
          Test.foo()        // ok 
          foo()             // ok 
          this.foo()        // ok 
          new Test().foo()  // java.lang.IncompatibleClassChangeError 
        } 
        
        def callFooFromInstanceMethod() { 
          Test.foo()       // ok 
          foo()            // java.lang.IncompatibleClassChangeError 
          this.foo()       // java.lang.IncompatibleClassChangeError 
          new Test().foo() // java.lang.IncompatibleClassChangeError 
        } 
      } 
      
      Test.callFooFromStaticMethod() 
      new Test().callFooFromInstanceMethod() 
      

      As indicated, several invocations throw an IncompatibleClassChangeError. I would expect all of them to succeed, just as they do for non-private static methods.

        Issue Links

          Activity

          Mark Thomas made changes -
          Workflow jira [ 12967185 ] Default workflow, editable Closed status [ 12974917 ]
          Mark Thomas made changes -
          Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
          Mark Thomas made changes -
          Workflow jira [ 12731466 ] Default workflow, editable Closed status [ 12743400 ]
          Mark Thomas made changes -
          Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
          Jochen Theodorou made changes -
          Fix Version/s 1.7 beta 1 [ 14014 ]
          Resolution Fixed [ 1 ]
          Fix Version/s 1.5.8 [ 14630 ]
          Status Open [ 1 ] Closed [ 6 ]
          Jochen Theodorou made changes -
          Component/s class generator [ 10443 ]
          Component/s bytecode [ 11336 ]
          Fix Version/s 1.6-rc-1 [ 14009 ]
          Assignee Jochen Theodorou [ blackdrag ]
          Fix Version/s 1.6 [ 13832 ]
          Jochen Theodorou made changes -
          Link This issue depends upon GROOVY-3100 [ GROOVY-3100 ]
          Guillaume Delcroix made changes -
          Fix Version/s 1.6 [ 13832 ]
          Fix Version/s 1.5.2 [ 13939 ]
          Guillaume Delcroix made changes -
          Fix Version/s 1.5.2 [ 13939 ]
          Paul King made changes -
          Description Like Java, Groovy allows for static methods to be called in different ways. Surprisingly, not all of them work for private static methods. Specifically:

          -----
          class Test {
            // all errors go away if method is declared non-private
            private static foo() {}
            
            static callFooFromStaticMethod() {
              Test.foo() // ok
              foo() // ok
              this.foo() // ok
              new Test().foo() // java.lang.IncompatibleClassChangeError
            }
            
            def callFooFromInstanceMethod() {
              Test.foo() // ok
              foo() // java.lang.IncompatibleClassChangeError
              this.foo() // java.lang.IncompatibleClassChangeError
              new Test().foo() // java.lang.IncompatibleClassChangeError
            }
          }

          Test.callFooFromStaticMethod()
          new Test().callFooFromInstanceMethod()
          -----

          As indicated, several invocations throw an IncompatibleClassChangeError. I would expect all of them to succeed, just as they do for non-private static methods.
          Like Java, Groovy allows for static methods to be called in different ways. Surprisingly, not all of them work for private static methods. Specifically:

          {code}
          class Test {
            // all errors go away if method is declared non-private
            private static foo() {}
            
            static callFooFromStaticMethod() {
              Test.foo() // ok
              foo() // ok
              this.foo() // ok
              new Test().foo() // java.lang.IncompatibleClassChangeError
            }
            
            def callFooFromInstanceMethod() {
              Test.foo() // ok
              foo() // java.lang.IncompatibleClassChangeError
              this.foo() // java.lang.IncompatibleClassChangeError
              new Test().foo() // java.lang.IncompatibleClassChangeError
            }
          }

          Test.callFooFromStaticMethod()
          new Test().callFooFromInstanceMethod()
          {code}

          As indicated, several invocations throw an IncompatibleClassChangeError. I would expect all of them to succeed, just as they do for non-private static methods.
          pnw made changes -
          Field Original Value New Value
          Attachment StaticCalls.groovy [ 31296 ]
          Peter Niederwieser created issue -

            People

            • Assignee:
              Jochen Theodorou
              Reporter:
              Peter Niederwieser
            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development