JDK-8154203 : Use StackWalker instead of the now-deprecated sun.reflect.Reflection class
  • Type: Bug
  • Component: javafx
  • Sub-Component: fxml
  • Affected Version: 9
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2016-04-13
  • Updated: 2016-04-25
  • Resolved: 2016-04-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9Fixed
Related Reports
Relates :  
Description
The javafx.fxml module uses two classes from the sun.reflect package:

sun.reflect.CallerSensitive
sun.reflect.Reflection

With JDK-8137058 most classes in the sun.reflect package are moving to the jdk.internal.reflect package, including those two. We either need to find an alternative using public API or react to the move prior to JDK-8137058 going into 9-dev.
Comments
Changeset: 70f6fa01a32c Author: kcr Date: 2016-04-14 14:16 -0700 URL: http://hg.openjdk.java.net/openjfx/9-dev/rt/rev/70f6fa01a32c
14-04-2016

+1
14-04-2016

http://cr.openjdk.java.net/~kcr/8154203/webrev.00/ Tested with existing JDK 9 EA build and verified that the StackWalker::getCallerClass returns the same answer as the internal Reflection::getCallerClass method (and without the need for the @CallerSensitive annotation).
14-04-2016

After some further digging, we are only using the CallerSensitive annotation and the Reflection class to get the calling class for some methods in FXMLLoader. In JDK 9 there is a public API replacement for this using the java.lang.StackWalker class. We should switch to using this, which will eliminate the problem entirely. The basic pattern will be: private static final StackWalker walker = AccessController.doPrivileged((PrivilegedAction<StackWalker>) () -> StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE)); public ... someMethod(...) { Class caller = walker.getCallerClass(); ...
14-04-2016