Oracle Resurrects getCallerClass, At Least for Now

| by Victor Grazi Follow 21 Followers on Aug 05, 2013. Estimated reading time: 1 minute |

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

Adoption Stage

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.

Tell us what you think

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

Email me replies to any of my messages in this thread

Pffft ... by Kit Davies


Re: Pffft ... by Victor Grazi

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

Email me replies to any of my messages in this thread

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

Email me replies to any of my messages in this thread

2 Discuss

Educational Content

Login to InfoQ to interact with what matters most to you.

Recover your password...


Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.


More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.


Stay up-to-date

Set up your notifications and don't miss out on content that matters to you