groovy

Cannot call static meta-method defined on parent class in static block of descendant

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Won't Fix
  • Affects Version/s: 1.5.6
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:
    OS X, Java 1.5
  • Testcase included:
    yes
  • Number of attachments :
    0

Description

The following test case fails:

#!/usr/bin/env groovy

Object.metaClass.'static'.helloWorld = {
println "Hello world!"
}

class MyClass {
static { helloWorld() }
}

def myClass = new MyClass ()

The above code fails with the following exception:

Caught: java.lang.ExceptionInInitializerError at
DefStaticProperty.class$(DefStaticProperty.groovy) at
DefStaticProperty.run(DefStaticProperty.groovy:13) at
DefStaticProperty.main(DefStaticProperty.groovy)

Activity

Hide
Paul King added a comment -

As a workaround, this works:

Object.metaClass.static.helloWorld = { println "Hello world!" }

class MyClass {
    static { Object.helloWorld() }
}

def myClass = new MyClass ()
Show
Paul King added a comment - As a workaround, this works:
Object.metaClass.static.helloWorld = { println "Hello world!" }

class MyClass {
    static { Object.helloWorld() }
}

def myClass = new MyClass ()
Hide
Guillaume Laforge added a comment -

This may be potentially set up as "won't fix"

Show
Guillaume Laforge added a comment - This may be potentially set up as "won't fix"

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: