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

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Development