Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Oracle Resurrects getCallerClass, At Least for Now

Oracle Resurrects getCallerClass, At Least for Now

Leia em Português

Lire ce contenu en français


Oracle announced in early July that the sun.reflect.Reflection.getCallerClass() Java method was being discontinued.  Now the firm has relented, with Oracle Java Platform Group chief architect Mark Reinhold tweeting the following notification on Thursday:

@CedricChampeau @glaforge We're going to restore getCallerClass(int) in 7u40. The fate of this method in 8 remains to be seen.

Cédric Champeau retweeted with the following comment:

Good news: the jdk guys decided to revert the behavior of getCallerClass in 1.7u40 and 1.8. #groovy and logging systems won't be broken :-)

Champeau is a prime committer on the Groovy programming language working at Pivotal, a division of VMWare, which also owns SpringSource, current backer of Groovy. Guillaume Laforge is SpringSource's head of Groovy development.

The sun.reflect.Reflection.getCallerClass() method works by returning the class instance of the method x frames up the call stack, with the Reflect class itself at position 0. getCallerClass() provides a mechanism for determining a caller's class in order to implement "Caller Sensitive" behavior, a strategy that allows applications to vary behavior based on the calling class or other classes in the call stack.

Oracle is quick to caution that calls such as getCallerClass() and any others in any sun.* package may be brittle and inconsistent, for reasons described in their article  "Why Developers Should Not Write Programs That Call 'sun' Packages". The deprecation announcement was being tracked on the OTN issue tracker.

Cédric Champeau exposed the deprecation early on because Groovy relies on that method call.

Not only is Groovy impacted, but Grails has also posted a related bug on their issue tracker.

A scan of some of the public source code search engines including GitHub reveals dependencies on getCallerClass() in a range of projects, including several active Oracle projects such as Project Jigsaw and Project Lambda, as well as third party projects such as IntelliJ IDEA.


Rate this Article


Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

  • Pffft ...

    by Kit Davies,

    Your message is awaiting moderation. Thank you for participating in the discussion.


  • Re: Pffft ...

    by Victor Grazi,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Probably works most of the time. Although if you are using this method you probably have some exotic use case, so all bets are off

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p