Turn: Oracle deprecated Sun.reflect.Reflection.getCallerClass

Source: Internet
Author: User
Tags deprecated

Http://www.infoq.com/cn/news/2013/07/Oracle-Removes-getCallerClass

As Java developers, we often ignore @deprecated annotations and continue to use them, even though we know that Oracle will get this tag at some point, but still fantasize that these tags are as indelible as stone.

Starting with JDK 7u40, Oracle has deprecated the Reflection.getcallerclass (int) method that is not easily understood in the Sun.reflect.package package. In Java 7, you can continue to use this method by setting the Java command-line option Djdk.reflect.allowGetCallerClass. However, in Java 8 and later, this method will be completely removed, and invoking it will result in a unsupportedoperationexception exception.

According to the Java documentation, the reflection class is located at the 0-frame position in the call stack, which returns the class from Frame x in the call stack starting at 0 frames. In summary, the Getcallerclass method provides a mechanism that can be used to determine the caller, thus implementing the behavior of the "Caller sensitive", which adjusts its own behavior based on the calling class or other classes in the call stack.

The JDK team wants to know how the Getcallerclass method is used in the application and can modify the code so that it no longer relies on any sun.* APIs. You can join the OPENJDK core-dev-libs mailing list to get feedback.

For years, Oracle has been reminding developers that the method of calling the Sun.* package is dangerous. In this regard, readers can read the explanatory article on the Oracle Blog "Why the developer should not call the ' sun ' package." In summary, using these deprecated features is prone to problems. As the platform changes, they may be transferred, deleted, or changed semantics at any time.

However, you do not have to lose faith if you use the behavior of the perceived caller. The JDK Enhancement proposal (JEP176) calls for improved security of the implementation of the JDK approach, replacing the existing manual maintenance method list with a mechanism that can reliably identify the caller-aware method.

Continue to follow this issue to access the Oracle bug database.

refer to the original English text: Oracle discontinuing Sun.reflect.Reflection.getCallerClass

Thank Ma Guoyao for the review of this article.

Turn: Oracle deprecated Sun.reflect.Reflection.getCallerClass

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.