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

Calling a static method of itself in an inner class causes ClassCastException

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3.0-rc-2
    • 2.3.4, 2.4.0-beta-2
    • None
    • None
    • Groovy Version: 2.3.0-rc-2 JVM: 1.8.0_05 Vendor: Oracle Corporation OS: Mac OS X

    Description

      class Foo1 {
        static call_directly() {
          foo()
        }
        static call_inClosure() {
          {-> foo() }.call()
        }
        static foo() {
          "FOO"
        }
      }
      class Foo2 {
        // 'private' and 'static' don't affect this issue.
        class Bar {
          static call_directly() {
            foo()
          }
          static call_inClosure() {
            {-> foo() }.call()
          }
          static call_inClosure_others() {
            {-> Foo1.foo() }.call()
          }
          static foo() {
            "FOO"
          }
        }
      }
      
      assert Foo1.call_directly() == 'FOO'
      assert Foo1.call_inClosure() == 'FOO' // -- [1]
      
      assert Foo2.Bar.call_directly() == 'FOO'
      GroovyAssert.shouldFail(ClassCastException) { // WHY?? -- [2]
        Foo2.Bar.call_inClosure()
      }
      assert Foo2.Bar.call_inClosure_others() == 'FOO' // -- [3]
      

      [1] It's no problem in a root class.
      [2] ClassCastException occurs.
      [3] It's no problem to call a other class's static method.

      Attachments

        Activity

          People

            paulk Paul King
            nobeans Yasuharu Nakano
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: