Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-2409

Problems calling private static methods

    XMLWordPrintableJSON

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.

      Attachments

        Issue Links

          Activity

            People

              blackdrag Jochen Theodorou
              pniederw Peter Niederwieser
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: