BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

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

Adoption
Style

BT