Oracle Resurrects getCallerClass, At Least for Now

by Victor Grazi on Aug 05, 2013 |

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.

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
General Feedback
Marketing and all content copyright © 2006-2016 C4Media Inc. hosted at Contegix, the best ISP we've ever worked with.
Privacy policy

We notice you're using an ad blocker

We understand why you use ad blockers. However to keep InfoQ free we need your support. InfoQ will not provide your data to third parties without individual opt-in consent. We only work with advertisers relevant to our readers. Please consider whitelisting us.